[8132] | 1 | /*
|
---|
| 2 | * Copyright 2002-2015 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 | */
|
---|
| 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 https://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 | @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 | }
|
---|