exception implicit objects
1. The JSP implicit exception object is an instance of thejava.lang.Throwable class.
Example: main.jsp
ShowError.jsp
2. JSP gives you an option to specify Error Page for each JSP. Whenever the page throws an exception, the JSP container automatically invokes the error page.
3. And is only available in error pages. Following is the list of important methods available in the Throwable class..
Methods:
1.public String getMessage() Returns a detailed message about the exception that has occurred. This message is initialized in the Throwable constructor. |
2. public Throwable getCause() Returns the cause of the exception as represented by a Throwable object. |
3.public String toString() Returns the name of the class concatenated with the result of getMessage() |
4.public void printStackTrace() Prints the result of toString() along with the stack trace to System.err, the error output stream. |
5.public StackTraceElement [] getStackTrace() Returns an array containing each element on the stack trace. The element at index 0 represents the top of the call stack, and the last element in the array represents the method at the bottom of the call stack. |
6.public Throwable fillInStackTrace() Fills the stack trace of this Throwable object with the current stack trace, adding to any previous information in the stack trace. |
Example: main.jsp
<%@ page errorPage="ShowError.jsp" %> <html> <head> <title>Error Handling Example</title> </head> <body> <% // Throw an exception to invoke the error page int x = 1; if (x == 1) { throw new RuntimeException("Error condition!!!"); } %> </body> </html> |
ShowError.jsp
<%@ page isErrorPage="true" %> <html> <head> <title>Show Error Page</title> </head> <body> <h1>Opps...</h1> <p>Sorry, an error occurred.</p> <p>Here is the exception stack trace: </p> <pre> <% exception.printStackTrace(response.getWriter()); %> </pre> </body> </html> |
Output:
java.lang.RuntimeException: Error condition!!! ...... Opps... Sorry, an error occurred. Here is the exception stack trace: |
Great Article
ReplyDeleteJava Projects for Engineering Students of Computer Science
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog.
ReplyDeleterpa training in bangalore
best rpa training in bangalore
RPA training in bangalore
rpa course in bangalore
rpa training in chennai
rpa online training
This is my 1st visit to your web... But I'm so impressed with your content. Good Job!
ReplyDeleteAWS Training in pune
AWS Online Training