|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.rblasch.convert; |
|
17 |
| |
|
18 |
| import java.io.PrintStream; |
|
19 |
| import java.io.PrintWriter; |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| public abstract class AbstractRuntimeException extends RuntimeException { |
|
25 |
| private Throwable cause = this; |
|
26 |
| |
|
27 |
0
| public AbstractRuntimeException() {
|
|
28 |
| } |
|
29 |
| |
|
30 |
126
| public AbstractRuntimeException(final String message) {
|
|
31 |
126
| super(message);
|
|
32 |
| } |
|
33 |
| |
|
34 |
0
| public AbstractRuntimeException(final String message, final Throwable cause) {
|
|
35 |
0
| super(message);
|
|
36 |
0
| this.cause = cause;
|
|
37 |
| } |
|
38 |
| |
|
39 |
3
| public AbstractRuntimeException(final Throwable cause) {
|
|
40 |
3
| super(cause == null ? null : cause.toString());
|
|
41 |
3
| this.cause = cause;
|
|
42 |
| } |
|
43 |
| |
|
44 |
0
| public Throwable getCause() {
|
|
45 |
0
| return (cause == this ? null : cause);
|
|
46 |
| } |
|
47 |
| |
|
48 |
0
| public synchronized Throwable initCause(final Throwable cause) {
|
|
49 |
0
| if (this.cause != this)
|
|
50 |
0
| throw new IllegalStateException("Can't overwrite cause");
|
|
51 |
0
| if (cause == this)
|
|
52 |
0
| throw new IllegalArgumentException("Self-causation not permitted");
|
|
53 |
0
| this.cause = cause;
|
|
54 |
0
| return this;
|
|
55 |
| } |
|
56 |
| |
|
57 |
0
| public void printStackTrace() {
|
|
58 |
0
| synchronized (System.err) {
|
|
59 |
0
| printStackTrace(System.err);
|
|
60 |
| } |
|
61 |
| } |
|
62 |
| |
|
63 |
0
| public void printStackTrace(final PrintStream s) {
|
|
64 |
0
| synchronized (s) {
|
|
65 |
0
| super.printStackTrace(s);
|
|
66 |
| |
|
67 |
0
| final Throwable ourCause = getCause();
|
|
68 |
0
| if (ourCause != null) {
|
|
69 |
0
| s.println("Caused by: " + ourCause);
|
|
70 |
0
| ourCause.printStackTrace(s);
|
|
71 |
| } |
|
72 |
| } |
|
73 |
| } |
|
74 |
| |
|
75 |
0
| public void printStackTrace(final PrintWriter s) {
|
|
76 |
0
| synchronized (s) {
|
|
77 |
0
| super.printStackTrace(s);
|
|
78 |
| |
|
79 |
0
| final Throwable ourCause = getCause();
|
|
80 |
0
| if (ourCause != null) {
|
|
81 |
0
| s.println("Caused by: " + ourCause);
|
|
82 |
0
| ourCause.printStackTrace(s);
|
|
83 |
| } |
|
84 |
| } |
|
85 |
| } |
|
86 |
| } |