views:

361

answers:

1

Hi

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?

A: 

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?

air_blob
well i have similar problem in the template i have a tag, this tag throws exception and somehow it does not render error controller action (defined in url mapping 500). Instead it renders up to the error and then prints out output from error controller i created. Redirection is not correct if there is error on the site you dont want crawlers to catch redirect and then 500. you should just give them corresponding 5xx code i guess. how to clean output buffer and replace it all with output from error handling controller action?
Art79
I think for this problem it would be much better to make sure, that your taglib doesn't throw any exceptions - further, if it does, why do you want to present a full page HTTP error and not a custom error message rendered by the taglib? Could you provide any taglib code?
air_blob