- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to handle an exception in JSP?
The <c:catch> tag catches any Throwable that occurs in its body and optionally exposes it. It is used for error handling and to deal more gracefully with the problem.
Attribute
The <c:catch> tag has the following attributes −
Attribute | Description | Required | Default |
---|---|---|---|
var | The name of the variable to hold the java.lang.Throwable if thrown by elements in the body. | No | None |
Example
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> <html> <head> <title><c:catch> Tag Example</title> </head> <body> <c:catch var ="catchException"> <% int x = 5/0;%> </c:catch> <c:if test = "${catchException != null}"> <p>The exception is : ${catchException} <br /> There is an exception: ${catchException.message}</p> </c:if> </body> </html>
The above code will generate the following result −
The exception is : java.lang.ArithmaticException: / by zero There is an exception: / by zero
- Related Articles
- How to handle an exception in Python?
- How to handle an exception in JShell in Java 9?
- How to handle an exception using lambda expression in Java?\n
- How to handle Python exception in Threads?
- How to handle the Runtime Exception in Java?
- How do you handle an exception thrown by an except clause in Python?
- How to handle the exception using UncaughtExceptionHandler in Java?
- How to handle python exception inside if statement?
- How to handle error object in JSP using JSTL tags?
- How to handle exception inside a Python for loop?
- How to handle a python exception within a loop?
- How can we create an exception filter to handle unhandled exceptions in C#\nASP.NET WebAPI?
- How to use the try-finally clause to handle exception in Python?
- How to handle Java Array Index Out of Bounds Exception?
- What is an exception Object in JSP? What type of exceptions can occur in a JSP page?

Advertisements