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

Last change on this file since 10865 was 10862, checked in by Don-vip, 8 years ago

update to metadata-extractor 2.9.1

File size: 2.9 KB
Line 
1/*
2 * Copyright 2002-2016 Drew Noakes
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21package com.drew.lang;
22
23import com.drew.lang.annotations.NotNull;
24import com.drew.lang.annotations.Nullable;
25
26import java.io.PrintStream;
27import java.io.PrintWriter;
28
29/**
30 * Represents a compound exception, as modelled in JDK 1.4, but
31 * unavailable in previous versions. This class allows support
32 * of these previous JDK versions.
33 *
34 * @author Drew Noakes https://drewnoakes.com
35 */
36public class CompoundException extends Exception
37{
38 private static final long serialVersionUID = -9207883813472069925L;
39
40 @Nullable
41 private final Throwable _innerException;
42
43 public CompoundException(@Nullable String msg)
44 {
45 this(msg, null);
46 }
47
48 public CompoundException(@Nullable Throwable exception)
49 {
50 this(null, exception);
51 }
52
53 public CompoundException(@Nullable String msg, @Nullable Throwable innerException)
54 {
55 super(msg);
56 _innerException = innerException;
57 }
58
59 @Nullable
60 public Throwable getInnerException()
61 {
62 return _innerException;
63 }
64
65 @Override
66 @NotNull
67 public String toString()
68 {
69 StringBuilder string = new StringBuilder();
70 string.append(super.toString());
71 if (_innerException != null) {
72 string.append("\n");
73 string.append("--- inner exception ---");
74 string.append("\n");
75 string.append(_innerException.toString());
76 }
77 return string.toString();
78 }
79
80 @Override
81 public void printStackTrace(@NotNull PrintStream s)
82 {
83 super.printStackTrace(s);
84 if (_innerException != null) {
85 s.println("--- inner exception ---");
86 _innerException.printStackTrace(s);
87 }
88 }
89
90 @Override
91 public void printStackTrace(@NotNull PrintWriter s)
92 {
93 super.printStackTrace(s);
94 if (_innerException != null) {
95 s.println("--- inner exception ---");
96 _innerException.printStackTrace(s);
97 }
98 }
99
100 @Override
101 public void printStackTrace()
102 {
103 super.printStackTrace();
104 if (_innerException != null) {
105 System.err.println("--- inner exception ---");
106 _innerException.printStackTrace();
107 }
108 }
109}
Note: See TracBrowser for help on using the repository browser.