This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

Question

 
Xiaochen Du
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question:
<html><body>
<%@ page isThreadSafe="false" %>
<%! int j=0; %>
<%
for (int i=0; i<10; i++)
{
out.print("The value of j is " + j + "<br>");
j++;
Thread.currentThread().sleep(100);
}
%>
</body></html>

Why there is no need of exception capture outside sleep()?
Thanks
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3819
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The service() method of a servlet can only throw ServletException or IOException (or there subclasses). So all other exceptions have to be caught. Servlet generated by Tomcat for your JSP is no exception. It puts all the code in a try/catch block as shown below:
 
Andy Wong
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So does that mean we do not need to put any try/catch code in the JSP page if the exception is not ServletException or IOException since the translated Servlet code will handle it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic