• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wrapping a business exception in ServletException in doPost()

 
Ranch Hand
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic