English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Biblioteca de Tags Padrão do JSP
<c:catch> é usado principalmente para lidar com situações de exceções geradas e armazenar as informações de erro.
<c:catch var="<string>"> ... </c:catch>
A tag <c:catch> tem os seguintes atributos:
Atributo | Descrição | Necessário? | Valor Padrão |
---|---|---|---|
var | Variável usada para armazenar informações de erro | Não | Nenhum |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>Exemplo de Tag c:catch</title> </head> <body> <c:catch var ="catchException"> <% int x = 5/0;%> </c:catch> <c:if test = "${catchException != null}"> <p>A exceção é: ${catchException} <br /> Ocorreu uma exceção: ${catchException.message}</p> </c:if> </body> </html>
Resultado da execução do exemplo acima:
A exceção é: java.lang.ArithmeticException: / por zero Ocorreu uma exceção: / por zero