Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Wrapping a business exception in ServletException in doPost()

 
Bindu Lakhanpal
Ranch Hand
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!