Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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: 3880
12
  • 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?
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!