source: josm/trunk/src/com/drew/lang/CompoundException.java@ 5822

Last change on this file since 5822 was 4231, checked in by stoecker, 13 years ago

add signpost and metadata extractor code to repository directly

File size: 2.5 KB
Line 
1/*
2 * This is public domain software - that is, you can do whatever you want
3 * with it, and include it software that is licensed under the GNU or the
4 * BSD license, or whatever other licence you choose, including proprietary
5 * closed source licenses. I do ask that you leave this header in tact.
6 *
7 * If you make modifications to this code that you think would benefit the
8 * wider community, please send me a copy and I'll post it on my site.
9 *
10 * If you make use of this code, I'd appreciate hearing about it.
11 * drew@drewnoakes.com
12 * Latest version of this software kept at
13 * http://drewnoakes.com/
14 */
15package com.drew.lang;
16
17import java.io.PrintStream;
18import java.io.PrintWriter;
19
20/**
21 * Represents a compound exception, as modelled in JDK 1.4, but
22 * unavailable in previous versions. This class allows support
23 * of these previous JDK versions.
24 */
25public class CompoundException extends Exception
26{
27 private final Throwable _innnerException;
28
29 public CompoundException(String msg)
30 {
31 this(msg, null);
32 }
33
34 public CompoundException(Throwable exception)
35 {
36 this(null, exception);
37 }
38
39 public CompoundException(String msg, Throwable innerException)
40 {
41 super(msg);
42 _innnerException = innerException;
43 }
44
45 public Throwable getInnerException()
46 {
47 return _innnerException;
48 }
49
50 public String toString()
51 {
52 StringBuffer sbuffer = new StringBuffer();
53 sbuffer.append(super.toString());
54 if (_innnerException != null) {
55 sbuffer.append("\n");
56 sbuffer.append("--- inner exception ---");
57 sbuffer.append("\n");
58 sbuffer.append(_innnerException.toString());
59 }
60 return sbuffer.toString();
61 }
62
63 public void printStackTrace(PrintStream s)
64 {
65 super.printStackTrace(s);
66 if (_innnerException != null) {
67 s.println("--- inner exception ---");
68 _innnerException.printStackTrace(s);
69 }
70 }
71
72 public void printStackTrace(PrintWriter s)
73 {
74 super.printStackTrace(s);
75 if (_innnerException != null) {
76 s.println("--- inner exception ---");
77 _innnerException.printStackTrace(s);
78 }
79 }
80
81 public void printStackTrace()
82 {
83 super.printStackTrace();
84 if (_innnerException != null) {
85 System.err.println("--- inner exception ---");
86 _innnerException.printStackTrace();
87 }
88 }
89}
Note: See TracBrowser for help on using the repository browser.