| 1 | /*
|
|---|
| 2 | * Copyright 2002-2012 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 | * http://drewnoakes.com/code/exif/
|
|---|
| 19 | * http://code.google.com/p/metadata-extractor/
|
|---|
| 20 | */
|
|---|
| 21 | package com.drew.lang;
|
|---|
| 22 |
|
|---|
| 23 | import com.drew.lang.annotations.NotNull;
|
|---|
| 24 | import com.drew.lang.annotations.Nullable;
|
|---|
| 25 |
|
|---|
| 26 | import java.io.PrintStream;
|
|---|
| 27 | import 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 http://drewnoakes.com
|
|---|
| 35 | */
|
|---|
| 36 | public 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 | @NotNull
|
|---|
| 66 | public String toString()
|
|---|
| 67 | {
|
|---|
| 68 | StringBuilder string = new StringBuilder();
|
|---|
| 69 | string.append(super.toString());
|
|---|
| 70 | if (_innerException != null) {
|
|---|
| 71 | string.append("\n");
|
|---|
| 72 | string.append("--- inner exception ---");
|
|---|
| 73 | string.append("\n");
|
|---|
| 74 | string.append(_innerException.toString());
|
|---|
| 75 | }
|
|---|
| 76 | return string.toString();
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | public void printStackTrace(@NotNull PrintStream s)
|
|---|
| 80 | {
|
|---|
| 81 | super.printStackTrace(s);
|
|---|
| 82 | if (_innerException != null) {
|
|---|
| 83 | s.println("--- inner exception ---");
|
|---|
| 84 | _innerException.printStackTrace(s);
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | public void printStackTrace(@NotNull PrintWriter s)
|
|---|
| 89 | {
|
|---|
| 90 | super.printStackTrace(s);
|
|---|
| 91 | if (_innerException != null) {
|
|---|
| 92 | s.println("--- inner exception ---");
|
|---|
| 93 | _innerException.printStackTrace(s);
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | public void printStackTrace()
|
|---|
| 98 | {
|
|---|
| 99 | super.printStackTrace();
|
|---|
| 100 | if (_innerException != null) {
|
|---|
| 101 | System.err.println("--- inner exception ---");
|
|---|
| 102 | _innerException.printStackTrace();
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 | }
|
|---|