• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Filter and uncaughtExceptions

 
Richard Olson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Requesting help re: a Java filter which logs HTTP responses and requests. The main sticking point at the moment, capturing an uncaughtException.

The Java filter’s doFilter contains the following entry:
Thread.currentThread().setUncaughtExceptionHandler(new HandleExceptionHandler());

The called inner class, HandleExceptionHandler contains:
public static class HandleExceptionHandler implements Thread.UncaughtExceptionHandler {
public void uncaughtException(Thread t, Throwable e) {

logger.error("Thread " + t.getName() + " died, exception was: ");
logger.debug("Thread = " + t.getId());
logger.debug("\n stack trace = " + e);
}
}


My test code simply defines an Array of a set size then tries insert elements past the Array’s defined size which throws an expected, java.lang.ArrayIndexOutOfBoundsException: 5 in the browser.

My problem, looks like the Java filter’s doFilter() never calls the inner class, HandleExceptionHandler. Any ideas? I’m tearing my remaining hair out. The basic code works via a Java app, but never works when inserted in to a Java filter. I tried some of the code from http://www.coderanch.com/t/462822/Java-General/java/Logging-runtime-exceptions, but no help

Note, the code's tested on Tomcat 5.5.27 and Java 1.5.0_20

Thanks
 
thushara wijeratna
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is probably because the servlet logic that calls into doFilter() is already catching the exception. try this example, to get an idea:

 
Richard Olson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great, thanks for the suggestion
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!