开发者

Grails common exception handling in grails 1.1

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 ve开发者_JAVA技巧rsion?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜