Jsp-jstl-core-catch-tag

提供:Dev Guides
移動先:案内検索

JSTL-コア<c:catch>タグ

*<c:catch>* タグは、本文で発生する *Throwable* をキャッチし、オプションで公開します。 エラー処理および問題をより適切に処理するために使用されます。

属性

*<c:catch>* タグには次の属性があります-
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

<%@ 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 exception is : java.lang.ArithmaticException:/by zero
There is an exception:/by zero