Losing exception chains for RuntimeExceptions thrown by action methods

When my application gets an unexpected error, I catch the exception using a servlet filter, then

redirect to an error page that lets the user to "drill down" into an exception chain, using a "show

details" link to see the next getMessage() value in the chain.

However, JSF seems to cut off the exception chain for RuntimeExceptions coming out of action

methods. How do I prevent this?

It seems to convert any RuntimeException thrown from an action method into a

javax.faces.el.EvaluationException. The getMessage() of the EvaluationException returns the same

String as the getMessage() of the RuntimeException that came out of the action method, and

getCause() returns null.

So for example, if I have a test action method:

public String throwException2(){

RuntimeException re =new RuntimeException("Cause exception");

MyCustomRuntimeException customExc =new MyCustomRuntimeException("my runtime exception", exc);

int i = 1;

if (i == 1){

throw customExc;

}

returnnull;

}

then I have some code in my servlet filter that handles the exception, prepares it for the error display

page, and it prints a log message:

logger.debug("exception: " + exception.toString() );

if (exception.getCause() ==null){

logger.debug("Cause is null");

}else{

logger.debug("Cause is " + exception.getCause().toString() );

}

The log messages are:

09 Nov 2005 22:38:03,080 DEBUG ApplicationExceptionFilter : exception:

javax.servlet.ServletException: #{gridBean.throwException}: javax.faces.el.EvaluationException:

com.example.MyCustomRuntimeException: my runtime exception

09 Nov 2005 22:38:03,081 DEBUG ApplicationExceptionFilter : Cause isnull

Is there any way to make JSF chain MyCustomRuntimeException to the ServletException that it

throws? And why doesn't it do this anyways? It would seem to make sense... it is what caused the ServletException to be thrown.

Thanks,

Scott

[2866 byte] By [Scott_Moorea] at [2007-10-2 4:47:39]
# 1
Here is a workaround for Error Handling with an JSF Error Page. http://www.jroller.com/page/mert?entry=handling_errors_with_an_errror
mulderbabaa at 2007-7-16 0:52:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...