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