Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet exception  RSS feed

 
kiran nori
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can any one tell me under what circumstances a servlet exception is thrown and what are the best ways to handle it.
rgds
Kiran
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletException is a pretty general way of handling an exception in a servlet. Note that a ServletException is probably going to have a "root cause" attached to it.
You can put a try-catch around the code in your doGet and doPost methods...
try {.........
}catch(ServletException e){
Throwable t = e.getRootCause();
t.printStackTrace( System.err); // or write to a log or whatevr
}
I wrote a chapter on debugging servlets - available free at: http://www.lanw.com/books/servletjsp/default.htm
Bill

------------------
author of:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!