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

Exception Handling

 
Reshma Shanbhag
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I came across this question at j2eecertificate.com, the answer given is option 1. It would be helpful if one of you could help me know why the answer is option 1 and not option 3.





Answers Given are:

1. "ServletException was caught by TeaHouseServlet" is written to the web application's log file.



2. "IOException was caught by TeaHouseServlet" is written to the web application's log file.



3. "Throwable was caught by TeaHouseServlet" is written to the web application's log file.



4. None of the above because InvalidTeaException is not handled by the catch block.
 
Gaurav Gambhir
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Throwable class is the super class of all errors and exceptions. Its a generic one, doXXX() method of HttpServlet class declare ServletException and IOException in their throws clause.we cannot throw any exception other than these two or the runtime exception or their subclass, so to throw the other exceptions like InvalidTeaException, wrap it in ServletException and then rethrow the ServletException.The wrapped exception is called root exception.
Container use ServletException.getRootCause() method to extract the wrapped exception
 
Reshma Shanbhag
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats was helpful Gaurav.


Thanks,
Reshma
[ June 13, 2006: Message edited by: Reshma Pai ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic