2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2000, 2012 Oracle and/or its affiliates. All rights reserved.
8 package com.sleepycat.util;
11 * Unwraps nested exceptions by calling the {@link
12 * ExceptionWrapper#getCause()} method for exceptions that implement the
13 * {@link ExceptionWrapper} interface. Does not currently support the Java 1.4
14 * <code>Throwable.getCause()</code> method.
18 public class ExceptionUnwrapper {
21 * Unwraps an Exception and returns the underlying Exception, or throws an
22 * Error if the underlying Throwable is an Error.
24 * @param e is the Exception to unwrap.
26 * @return the underlying Exception.
28 * @throws Error if the underlying Throwable is an Error.
30 * @throws IllegalArgumentException if the underlying Throwable is not an
31 * Exception or an Error.
33 public static Exception unwrap(Exception e) {
35 Throwable t = unwrapAny(e);
36 if (t instanceof Exception) {
38 } else if (t instanceof Error) {
41 throw new IllegalArgumentException("Not Exception or Error: " + t);
46 * Unwraps an Exception and returns the underlying Throwable.
48 * @param e is the Exception to unwrap.
50 * @return the underlying Throwable.
52 public static Throwable unwrapAny(Throwable e) {
55 if (e instanceof ExceptionWrapper) {
56 Throwable e2 = ((ExceptionWrapper) e).getCause();