Grails common exception handling in grails 1.1

老子叫甜甜 提交于 2020-01-25 20:38:38

问题


Some one please tell me how to handle RunTimeExceptions in grails version1.1 .I have followed the following tutorial.I could not get it working.

http://blog.bruary.net/2008/03/grails-custom-exception-handling.html

I have MyException which extends RunTimeException .If this particular exception comes I want show different error page.Is it possible to achieve in grails 1.1 version?


回答1:


Can you provide some sample code, where some RuntimeException is thrown? It is difficult to answer your question properly, if you don't tell what your exact problem is.

As far as I could tell your from this point, your BootStrap.groovy should look something like this:

class BootStrap {
 def exceptionHandler

 def init = { servletContext ->

   exceptionHandler.exceptionMappings =
       [ 'NoSuchFlowExecutionException' :'/my/doIt',
         'java.lang.Exception' : '/error',
         'org.you.YourCustomException' : '/yourErrorController/yourErrorAction' ]
}

def destroy = { }

On the other side, in your code, you have to catch occuring RuntimeExceptions and transate them into your custom exception.

And here we are at the interesting point: Why do you want to do this? Wouldn't it be much more comfortable to redirect when RuntimeExceptions are thrown?



来源:https://stackoverflow.com/questions/2349957/grails-common-exception-handling-in-grails-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!