JSTL c:catchで例外の処理サンプル

形式
c:catch var="exception"
説明
var 例外を格納する変数の名前
body部   例外が発生する処理

JSPコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<c:catch var="exception">
<%
int a = 12 / 0;
%>
</c:catch>
<c:if test="${exception != null}">
<c:out value="${exception.message}" />
</c:if>
<c:catch var="exception"> <% int a = 12 / 0; %> </c:catch> <c:if test="${exception != null}"> <c:out value="${exception.message}" /> </c:if>
<c:catch var="exception">
  <%
    int a = 12 / 0;
  %>
</c:catch>

<c:if test="${exception != null}">
  <c:out value="${exception.message}" />
</c:if>

結果
/ by zero

JSTL

Posted by arkgame