Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaBeat question. error-page

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


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

ANS : A,C



I have doubt on given answer. Could you please focus some details on
this question.
Thanks in advance for your time!


Thanks,
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you explain what your doubts are. What do you think is the correct answer(s)?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,

Catching the exception means, I don't get, is it about putting the
code in the <c:catch> or using scriptlet (java way to handle the exception).

I know, setting errorPage attribute of the page directive in the page is
enough to make business error page to be called.


Thanks,
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it about putting the code in the <c:catch> or using scriptlet (java way to handle the exception).

No, it's about catching checked exceptions in a servlet. As you know, methods like doPost throw a ServletException or a IOException. How do you do when you have a business method throwing one of your custom Exception ? You can't throw it "as is" from doPost. What you can do is to catch the exception, wrap it as a new ServletException, and throw it from doPost. The container will then redirect you to the appropriate error page (the one you have defined in web.xml).
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Christophe,

Could you please give a line of code "exception is wrapped in the appropriate
ServletException and then thrown". I understand the DD configuration for the

<error-page>
<exception-type>...</exception-type>
<location>...</location>
</error-page>


Thanks for your reply!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christophe,

I appreciate your quick reply. I got that.

By the way you reply much quickly than Satou used to. Don't tell this
to Satao.

Thanks again,
[ July 29, 2007: Message edited by: Chandra Bhatt ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats a good post by OP.

But chandra, thats how mostly the applications are dealt with. Many of the checked exceptions are caught and rethrown as a different-but-custom exception after doing the necessary things in case of an exception.

A sample code makes the concept more clear!
 
Vishal Chugh
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As we are wrapping our Biz. exception into ServletException , so now our exception is finally ServletException not Biz. exception (while we are throwing it from catch block ) so mapping in DD should be from 'ServletException to error-page'

So according to above , D should be correct answer , howcome C ?

Thanks
Vishal Chugh
 
Vishal Chugh
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please suggest.

Thanks
Vishal Chugh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic