Friday, March 27, 2015

exceptions and example for exception in JSP

There are certain errors that you have in JSP and they are:

  1. Checked Exceptions: This exceptions are typically known as a user error problem which a programmer cannot see or which cannot be foreseen by the programmer. Ex: a file that is need to be opened by a program but the file is not found .
  2. Run-time Exception: It is a exception that occurs when some error are  avoided by a programmer.
  3. Errors: These are not exception but are clearly errors that might arise apart form user or programmer limit.


Example:

JSP File (index.jsp)

 <!DOCTYPE html>  
 <html>  
   <head>  
     <title>nirajanghimireyworkshop.blogspot.com</title>  
   </head>  
   <body>  
     <%  
       try {  
         int num = 1;  
         num = num / 0;  
         out.println("The answer is " + num);  
       } catch (Exception e) {  
         out.println("An exception occurred: " + e.getMessage());  
       }  
     %>  
   </body>  
 </html> 

No comments:

Post a Comment