1 | public class BaseException extends Exception↵ | | 1 | public class BaseRuntimeException extends RuntimeException↵
|
2 | {↵ | | 2 | {↵
|
3 | /** If this exception is wrapped around another it is stored here. */↵ | | 3 | /** If this exception is wrapped around another it is stored here. */↵
|
4 | private Throwable _wrapee;↵ | | 4 | private Throwable _wrapee;↵
|
|
5 | /**↵ | | 5 | /**↵
|
6 | * Default ctor. Creates an exception with an empty string ("")↵ | | 6 | * Default ctor. Creates an exception with an empty string ("")↵
|
7 | * as its message.↵ | | 7 | * as its message.↵
|
8 | */↵ | | 8 | */↵
|
9 | public BaseException()↵ | | 9 | public BaseRuntimeException()↵
|
10 | {↵ | | 10 | {↵
|
11 | this("");↵ | | 11 | this("");↵
|
12 | }↵ | | 12 | }↵
|
|
13 | /**↵ | | 13 | /**↵
|
14 | * Ctor specifying the message.↵ | | 14 | * Ctor specifying the message.↵
|
15 | *↵ | | 15 | *↵
|
16 | * @param msg The message.↵ | | 16 | * @param msg The message.↵
|
17 | */↵ | | 17 | */↵
|
18 | public BaseException(String msg)↵ | | 18 | public BaseRuntimeException(String msg)↵
|
19 | {↵ | | 19 | {↵
|
20 | super(msg != null ? msg : "");↵ | | 20 | super(msg != null ? msg : "");↵
|
21 | }↵ | | 21 | }↵
|
|
22 | /**↵ | | 22 | /**↵
|
23 | * Ctor specifying an exception that this one should↵ | | 23 | * Ctor specifying an exception that this one should↵
|
24 | * be wrapped around.↵ | | 24 | * be wrapped around.↵
|
25 | *↵ | | 25 | *↵
|
26 | * @param wrapee The wrapped exception.↵ | | 26 | * @param wrapee The wrapped exception.↵
|
27 | */↵ | | 27 | */↵
|
28 | public BaseException(Throwable wrapee)↵ | | 28 | public BaseRuntimeException(Throwable wrapee)↵
|
29 | {↵ | | 29 | {↵
|
30 | super(wrapee);↵ | | 30 | super(getMessageFromException(wrapee));↵
|
31 | _wrapee = wrapee;↵ | | 31 | _wrapee = wrapee;↵
|
32 | }↵ | | 32 | }↵
|
|
33 | public String toString()↵ | | 33 | public String toString()↵
|
34 | {↵ | | 34 | {↵
|
35 | if (_wrapee != null)↵ | | 35 | if (_wrapee != null)↵
|
36 | {↵ | | 36 | {↵
|
37 | return _wrapee.toString();↵ | | 37 | return _wrapee.toString();↵
|
38 | }↵ | | 38 | }↵
|
39 | return super.toString();↵ | | 39 | return super.toString();↵
|
40 | }↵ | | 40 | }↵
|
|
41 | public void printStackTrace()↵ | | 41 | public void printStackTrace()↵
|
42 | {↵ | | 42 | {↵
|
43 | if (_wrapee != null)↵ | | 43 | if (_wrapee != null)↵
|
44 | {↵ | | 44 | {↵
|
45 | _wrapee.printStackTrace();↵ | | 45 | _wrapee.printStackTrace();↵
|
46 | }↵ | | 46 | }↵
|
47 | else↵ | | 47 | else↵
|
48 | {↵ | | 48 | {↵
|
49 | super.printStackTrace();↵ | | 49 | super.printStackTrace();↵
|
50 | }↵ | | 50 | }↵
|
51 | }↵ | | 51 | }↵
|
|
52 | public void printStackTrace(PrintStream s)↵ | | 52 | public void printStackTrace(PrintStream s)↵
|
53 | {↵ | | 53 | {↵
|
54 | if (_wrapee != null)↵ | | 54 | if (_wrapee != null)↵
|
55 | {↵ | | 55 | {↵
|
56 | _wrapee.printStackTrace(s);↵ | | 56 | _wrapee.printStackTrace(s);↵
|
57 | }↵ | | 57 | }↵
|
58 | else↵ | | 58 | else↵
|
59 | {↵ | | 59 | {↵
|
60 | super.printStackTrace(s);↵ | | 60 | super.printStackTrace(s);↵
|
61 | }↵ | | 61 | }↵
|
62 | }↵ | | 62 | }↵
|
|
63 | public void printStackTrace(PrintWriter wtr)↵ | | 63 | public void printStackTrace(PrintWriter wtr)↵
|
64 | {↵ | | 64 | {↵
|
65 | if (_wrapee != null)↵ | | 65 | if (_wrapee != null)↵
|
66 | {↵ | | 66 | {↵
|
67 | _wrapee.printStackTrace(wtr);↵ | | 67 | _wrapee.printStackTrace(wtr);↵
|
68 | }↵ | | 68 | }↵
|
69 | else↵ | | 69 | else↵
|
70 | {↵ | | 70 | {↵
|
71 | super.printStackTrace(wtr);↵ | | 71 | super.printStackTrace(wtr);↵
|
72 | }↵ | | 72 | }↵
|
73 | }↵ | | 73 | }↵
|
|
74 | private static String getMessageFromException(Throwable th)↵ | | |
|
75 | {↵ | | |
|
76 | String rtn = "";↵ | | |
|
77 | if (th != null)↵ | | |
|
78 | {↵ | | |
|
79 | String msg = th.getMessage();↵ | | |
|
80 | if (msg != null)↵ | | |
|
81 | {↵ | | |
|
82 | rtn = msg;↵ | | |
|
83 | }↵ | | |
|
84 | }↵ | | |
|
85 | return rtn;↵ | | |
|
86 | }↵ | | |
|
|
87 | /**↵ | | 74 | /**↵
|
88 | * Retrieve the exception that this one is wrapped around. This can be↵ | | 75 | * Retrieve the exception that this one is wrapped around. This can be↵
|
89 | * <TT>null</TT>.↵ | | 76 | * <TT>null</TT>.↵
|
90 | *↵ | | 77 | *↵
|
91 | * @return The wrapped exception or <TT>null</TT>.↵ | | 78 | * @return The wrapped exception or <TT>null</TT>.↵
|
92 | */↵ | | 79 | */↵
|
93 | public Throwable getWrappedThrowable()↵ | | 80 | public Throwable getWrappedThrowable()↵
|
94 | {↵ | | 81 | {↵
|
95 | return _wrapee | | 82 | return _wrapee;↵
|
| | | 83 | }↵
|
|
| | | 84 | private static String getMessageFromException(Throwable th)↵
|
| | | 85 | {↵
|
| | | 86 | String rtn = "";↵
|
| | | 87 | if (th != null)↵
|
| | | 88 | {↵
|
| | | 89 | String msg = th.getMessage();↵
|
| | | 90 | if (msg != null)↵
|
| | | 91 | {↵
|
| | | 92 | rtn = msg;↵
|
| | | 93 | }↵
|
| | | 94 | }↵
|
| | | 95 | return rtn
|