Source code: com/drew/lang/CompoundException.java
1 package com.drew.lang;
2
3 import java.io.PrintStream;
4 import java.io.PrintWriter;
5
6 /**
7 * Represents a compound exception, as modelled in JDK 1.4, but
8 * unavailable in previous versions. This class allows support
9 * of these previous JDK versions.
10 */
11 public class CompoundException extends Exception
12 {
13 private Throwable _innnerException;
14
15 public CompoundException(String msg)
16 {
17 this(msg, null);
18 }
19
20 public CompoundException(Throwable exception)
21 {
22 this(null, exception);
23 }
24
25 public CompoundException(String msg, Throwable innerException)
26 {
27 super(msg);
28 _innnerException = innerException;
29 }
30
31 public Throwable getInnerException()
32 {
33 return _innnerException;
34 }
35
36 public String toString()
37 {
38 StringBuffer sbuffer = new StringBuffer();
39 sbuffer.append(super.toString());
40 if (_innnerException != null) {
41 sbuffer.append("\n");
42 sbuffer.append("--- inner exception ---");
43 sbuffer.append("\n");
44 sbuffer.append(_innnerException.toString());
45 }
46 return sbuffer.toString();
47 }
48
49 public void printStackTrace(PrintStream s)
50 {
51 super.printStackTrace(s);
52 if (_innnerException != null) {
53 s.println("--- inner exception ---");
54 _innnerException.printStackTrace(s);
55 }
56 }
57
58 public void printStackTrace(PrintWriter s)
59 {
60 super.printStackTrace(s);
61 if (_innnerException != null) {
62 s.println("--- inner exception ---");
63 _innnerException.printStackTrace(s);
64 }
65 }
66
67 public void printStackTrace()
68 {
69 super.printStackTrace();
70 if (_innnerException != null) {
71 System.err.println("--- inner exception ---");
72 _innnerException.printStackTrace();
73 }
74 }
75 }