//result.jsp
<%@ page errorPage="error.jsp" %>
<html>
<head>
<title>JSP Exception Handling</title>
</head>
<body>
<%
int a = 46;
int b = 0;
int result = a/b ;
%>
</body>
</html>
//error.jsp
<%@ page isErrorPage = "true" %>
<html>
<head>
<title>Exception Page</title>
</head>
<body>
<h3>Sorry an exception occured!</h3>
Exception is: <%= exception %>
</body>
</html>
<html>
<head>
<title>Exception handling in JSP using try catch blocks</title>
</head>
<body>
<%
try
{
int arr[] = {9,8,7,6,5,4,3};
int num = arr[10];
out.println("11th element of arr"+num);
}
catch (Exception exp)
{
out.println("Cannot find the given index: " + exp);
}
%>
</body>
</html>