• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Doubt on send Error

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is question from Enthuware mock test

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?

Select 2 correct options
a Catch the exception and use RequestDispatcher to forward the request to the error page.
b Don't catch the exception and define the 'exception to error-page' mapping in web.xml
c Catch the exception, wrap it into ServletException and define the 'business exception to error-page' mapping in web.xml
d Catch the exception, wrap it into ServletException, and define the 'ServletException to error-page' mapping in web.xml
e Don't do anything, the servlet container will automatically send a default error page.

The answer is a and c. I always get confused, Why cant 'd' be the answer?

Can we wrap the exception in to ServletException and then define Servlet exception instead of Business Exception?

What happen if we have to <exception-type>ServletException<exception-type>
<exception-type>BusinessException<exception-type> defined in web.xml.

Please clarify this.I read many times, but I could not get satisfactory answers
 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What happen if we have to <exception-type>ServletException<exception-type>
<exception-type>BusinessException<exception-type> defined in web.xml.



I presume the

to

is two....Note that you cannot declare

It should be

Same is true for the BusinessException....should be mentioned with the fully qualified name.

Coming to your question....if you have 2 error-page elements in the DD--one with ServletException and the other with BusinessException, then even if a BusinessException is thrown, the container does not show the error page associated with the BusinessException but it shows the one associated with ServletException(since that's the exception which is actually being thrown after wrapping the BusinessException with it)....the same page is shown if a ServletException itself is thrown in any other way(say any method throwing a ServletException)....so the error page is no more a specific one for the BusinessException....that's the reason you need a 'business exception to error-page' mapping.

Hope you got it.

And yeah, I guess one of the bartenders would soon come up with a warning regarding your name....please read the naming policy and change it before they do so.
 
reply
    Bookmark Topic Watch Topic
  • New Topic