Exception Handling in JSP

How will you handle the exception without sending to error page? How will you set a message detail to the exception object?

Questions by anithyus

Showing Answers 1 - 10 of 10 Answers

In JSP, you can use JSTL tag 


<c:catch var="exceptionObject">

</c:catch>

This tag will catch the exception and will assign the implicit exception object to the var defined as attribute above. Then you can use this var to get message or more information about the exception. This var will be object of Throwable which is superclass in Exception hierarchy.

Cheers

  Was this answer useful?  Yes

When ever Exception accoured redirect the cantrol to the Error page
<%@ page ErrorPage="error.jsp" %>

In Error page add the bellow line of code
<%@ page isErrorPage="true" %>
<%
out.println(" ");
PrintWriter pw=request.getWriter();
Exception.getPrintStakeTrace(pw);
out.println(" ");
%>

  Was this answer useful?  Yes

delindia

  • Jan 2nd, 2012
 

Example:


The exception will be thrown inside the catch:

<% int x = 5/0;%>



The exception is : ${catchException}

There is an exception: ${catchException.message}



  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions