Catch an Exception using EL

In this example we are going to catch an exception by using the EL. We can't prevent errors, but of course we can give the user a friendlier error response page. Instead of giving any error codes we should try to show some friendly messages.

Catch an Exception using EL

Catch an Exception using EL

        

In this example we are going to catch an exception by using the EL. We can't prevent errors, but of course we can give the user a friendlier error response page. Instead of giving any error codes we should try to show some friendly messages. 

In this example we are going to catch an exception using EL in the page where we are going to catch the exception. 

 

The code of the program is given below:

 

 

<%@ page errorPage = "ErrorPageOfJstl.jsp"%>
<html>
<head>
<title>Throwing an Exception</title>
</head>

<body>5 divided by 0 is 
<% int x = 5/0;%>
</body>
</html>

 

<%@ page isErrorPage = "true"%>
<html>
<body>
<img src = "/tapan/jsp/jspexamples/fruit.gif"><br>
You caused an exception ${pageContext.exception} on the server.
</body>
</html>

The output of the program is given below:

Download this example.