JSTL - Etiqueta principal <c: catch>
los <c:catch> la etiqueta atrapa cualquier Throwableque ocurre en su cuerpo y opcionalmente lo expone. Se utiliza para el manejo de errores y para tratar el problema con más elegancia.
Atributo
los <c:catch> La etiqueta tiene los siguientes atributos:
Atributo | Descripción | Necesario | Defecto |
---|---|---|---|
var | El nombre de la variable para contener java.lang.Throwable si lo arrojan elementos en el cuerpo. | No | Ninguna |
Ejemplo
<%@ 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>
El código anterior generará el siguiente resultado:
The exception is : java.lang.ArithmaticException: / by zero
There is an exception: / by zero