Cyntech’s Tech Blog

Icon

Technical tidbits; coding and I.T.

What the hell is causing this Servlet Exception?

Writing a Java web application?  Keep getting a servlet exception? Can’t work out what the bloody hell is causing it?  Well, I have news for you!

Use this little snippet of code to get to the root cause of the exception.

try {

    // Your code

} catch (ServletException e) {

    Throwable t = e.getRootCause();
    System.err.println("Root Cause of Servlet Exception: " +
         t.getMessage());
    t.printStackTrace();

}

This does require to be placed in the area that actually uses Servlet code, like Request filters or HTTP processing (obviously to be able to catch it, you have to be where it is thrown).

Category: Programming

Tagged: , ,

Leave a Reply