• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Wrapping a business exception in ServletException in doPost()

 
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:
 
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.

 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic