teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

2015/02/18 03:39

投稿

idledesu
idledesu

スコア259

answer CHANGED
@@ -3,41 +3,33 @@
3
3
  イメージは以下のような感じです。
4
4
 
5
5
  ◆例外ハンドラ(ExceptionHandler)を拡張
6
- ```lang-java
7
6
  public class CustomizeExceptionHandler extends ExceptionHandler {
8
7
 
9
- static Logger logger = Logger.getLogger(CustomizeExceptionHandler.class);
8
+ static Logger logger = Logger.getLogger(CustomizeExceptionHandler.class);
10
9
 
11
- public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, Act ionForm formInstance, HttpServletRequest request, HttpServletResponse response) throws ServletException {
12
- //ここに例外に関する処理を追加。
13
- //logger.error("例外発生: " + ex.getMessage());
14
- return super.execute(ex, ae, mapping, formInstance, request, response);
15
- }
10
+ public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response) throws ServletException {
11
+ //ここに例外に関する処理を追加。
12
+ //logger.error("例外発生: " + ex.getMessage());
13
+ return super.execute(ex, ae, mapping, formInstance, request, response);
16
14
  }
17
- ```
15
+ }
18
16
 
19
17
  ◆struts-config.xmlに拡張した例外ハンドラを追加
20
- ```lang-java
21
18
  <global-exceptions>
22
19
  <exception
23
- key="error.Exception"
20
+ key="error.Exception"
24
- type="java.lang.Throwable"
21
+ type="java.lang.Throwable"
25
- handler="examples.exceptions.CustomizeExceptionHandler" />
22
+ handler="examples.exceptions.CustomizeExceptionHandler" />
26
23
  </global-exceptions>
27
24
 
28
- ```
29
25
 
30
26
  ◆例外を握りつぶしていたら非チェック例外でラップする
31
- ```lang-java
32
27
  } catch (Exception e) {
33
- //何も処理なし
28
+ //何も処理なし
34
29
  }
35
30
 
36
- ```
37
31
  ↓変更
38
32
 
39
- ```lang-java
40
33
  } catch (Exception e) {
41
- throw new RuntimeException(e);
34
+ throw new RuntimeException(e);
42
- }
35
+ }
43
- ```