Howdy Ranchers!
I've got a problem. I have a
servlet, which makes some computations. Let's say that this Servlet can (and will) throw an Illegal Argument Exception. Then I want to wrap this exception into the ServletException and throw it from the doGet(-) method, just like that:
I am also printing the stack trace to be sure what I am throwing, and it shows:
javax.servlet.ServletException: Customer ID is invalid
at com.example.ocmjd.BookServlet.doGet(BookServlet.java:22)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
(...) // buch of low-level stack trace elements
So, I've got my ServletException and message shown in the stack trace - fine. Now, my web.xml relevant part looks like:
So, the container is thinking - "I've bumped into the ServletException and I (the mighty container) will pass the exception to the
/servletException.jsp file to cope with it":
And the result is:
Exception: java.lang.IllegalArgumentException
Message:
So, the exception is IllegalArgumentException - not a ServletException which I expected (as the IAE is just a cause for ServletException) and the message is empty.
Well, it looks like the container (?) is unwrapping the exception I am catching and serving just the cause of it. So the ${pageContext.exception} is the cause, not the real-one thrown exception.
Is it always like that? Can I access the original ServletException which was thrown from the Servlet? And, the most important, why is the container doing this to me? Why...?
Cheers!