01: package org.mockejb.interceptor;
02:
03: import java.io.PrintWriter;
04: import java.io.StringWriter;
05:
06: /**
07: * General-level exception used for various aspect/interceptor system exceptions.
08: * Support exception chaining for 1.3 users just in case.
09: *
10: * @author Alexander Ananiev
11: */
12: public class AspectException extends RuntimeException {
13:
14: private Throwable cause;
15:
16: /**
17: * Creates a new instance of <code>AspectException</code>.
18: * Appends the error stack of the cause to the message to remain 1.3 compliant.
19: * @param message error message
20: * @param cause cause of the exception
21: */
22: public AspectException(String message, Throwable cause) {
23: super (message + "\nCause:\n" + stackToString(cause));
24: this .cause = cause;
25: }
26:
27: public AspectException(Throwable cause) {
28: this ("", cause);
29: }
30:
31: public AspectException(String message) {
32: super (message);
33: }
34:
35: /**
36: * Returns the cause of this throwable or null if the cause is nonexistent
37: * or unknown.
38: *
39: * @return the cause of this throwable or null if the cause is
40: * nonexistent or unknown
41: *
42: */
43: public Throwable getCause() {
44: return cause;
45: }
46:
47: private static String stackToString(Throwable e) {
48: StringWriter stringWriter = new StringWriter();
49: e.printStackTrace(new PrintWriter(stringWriter));
50:
51: return stringWriter.toString();
52: }
53:
54: }
|