Creating your own JSP exception page

If exceptions occur in JSP pages that are not handled, you can make the engine redirect to an JSP or HTML error page. You can even have access to the exception occurred (the “implicit exception object”) if you set the isErrorPage attribute to true.

A divide by zero JSP:

<%-- Redirect all uncaught exceptions to errorpage.jsp --%>
<%@ page errorPage="errorpage.jsp"%>

<%
   int h = 10 / 0;
%>

errorpage.jsp:

<%-- provides access to the implicit exception object --%>
<%@ page isErrorPage="true" %>
<html>
<body>
   <h3>An error occurred!</h3>
   <%=exception%>
</body>
</html>

Test it out here:
Divide by zero JSP