| Author |
Wrapping a business exception in ServletException in doPost()
|
Bindu Lakhanpal
Ranch Hand
Joined: Oct 17, 2008
Posts: 163
|
|
This is from Enthuware:
Which of the following is a sensible way of sending an error page to the client in case of a business exception that extends from java.lang.Exception?
C. Catch the exception, wrap it into ServletException and define the 'business exception to error-page' mapping in web.xml----Answer
D.Catch the exception, wrap it into ServletException, and define the 'ServletException to error-page' mapping in web.xml
Why D is not an answer?
We have wrapped our business exception in ServletException and throwing ServletException so web.xml should have ServletException to error-page mapping.
Why C is correct? Since we are throwing ServletException why the mapping in web.xml should be businessException to error-page
They have explanation giving following code:
//in doPost() of AccountServlet
The error mapping in DD should be:
|
 |
Tripati Sahu
Greenhorn
Joined: Jul 11, 2009
Posts: 25
|
|
Suppose I want to configure 4-5 different kind of exceptions then how you will configure...
If we will configure servlet exception then it will always go fo it.
Guys please correct me If I am wrong.
|
 |
Bindu Lakhanpal
Ranch Hand
Joined: Oct 17, 2008
Posts: 163
|
|
Yes. And i read the "sensible way " in question .
But we are throwing a servletException and catching a business exception.
Or is it not the way it appears and it is actually business exception being thrown?
Howcome?
|
 |
Bindu Lakhanpal
Ranch Hand
Joined: Oct 17, 2008
Posts: 163
|
|
I got the answer in SRV.9.9.2 !
If no error-page declaration containing an exception-type fits using the
class-heirarchy match, and the exception thrown is a ServletException or
subclass thereof, the container extracts the wrapped exception, as defined by the
ServletException.getRootCause method. A second pass is made over the error
page declarations, again attempting the match against the error page declarations,
but using the wrapped exception instead.
|
 |
 |
|
|
subject: Wrapping a business exception in ServletException in doPost()
|
|
|