By: Prem Tiwari | Last Updated:
Exception Handling is a process of handling exceptional condition that might occur in your application. Exception Handling in JSP is much easier than Java Technology exception handling. Although JSP Technology also uses the same exception class object.
Example of isErrorPage and errorPage attribute
We can handle the exceptions in jsp by specifying error Page in the page directive, <%@ page errorPage = "errorPage.jsp">. If any exception will be thrown then the control to handle the exception will be passed to that error page where we can display a information to the user about what’s the reason behind throwing the exception.
Example of JSP isErrorPage and errorPage attributes
<%@ page errorPage="ShowError.jsp" %>
<title>Error Handling Example</title>
// Throw an exception to invoke the error page
boolean x = true;
throw new RuntimeException("Error Occured!!!");
<%@ page isErrorPage="true" %>
<p>Sorry, an error occurred.</p>
<p>Here is the exception stack trace: </p>
<% exception.printStackTrace(response.getWriter()); %>
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari