回答編集履歴
1
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
|
-
|
8
|
+
static Logger logger = Logger.getLogger(CustomizeExceptionHandler.class);
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
20
|
+
key="error.Exception"
|
24
|
-
|
21
|
+
type="java.lang.Throwable"
|
25
|
-
|
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
|
-
|
34
|
+
throw new RuntimeException(e);
|
42
|
-
}
|
35
|
+
}
|
43
|
-
```
|