• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question  RSS feed

 
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: 4106
34
  • 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
Boost this thread!