File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt on send Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt on send Error" Watch "Doubt on send Error" New topic

Doubt on send Error

Swetha S

Joined: Dec 06, 2006
Posts: 16
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
Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
What happen if we have to <exception-type>ServletException<exception-type>
<exception-type>BusinessException<exception-type> defined in web.xml.

I presume the
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) 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.

Turn on, tune in, drop out.
I agree. Here's the link:
subject: Doubt on send Error
jQuery in Action, 3rd edition