Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

ExceptionUnwrapper.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2000-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: ExceptionUnwrapper.java,v 12.2 2005/08/01 20:25:21 mark Exp $
00008  */
00009 
00010 package com.sleepycat.util;
00011 
00020 public class ExceptionUnwrapper {
00021 
00035     public static Exception unwrap(Exception e) {
00036 
00037         Throwable t = unwrapAny(e);
00038         if (t instanceof Exception) {
00039             return (Exception) t;
00040         } else if (t instanceof Error) {
00041             throw (Error) t;
00042         } else {
00043             throw new IllegalArgumentException("Not Exception or Error: " + t);
00044         }
00045     }
00046 
00054     public static Throwable unwrapAny(Throwable e) {
00055 
00056         while (true) {
00057             if (e instanceof ExceptionWrapper) {
00058                 Throwable e2 = ((ExceptionWrapper) e).getCause();
00059                 if (e2 == null) {
00060                     return e;
00061                 } else {
00062                     e = e2;
00063                 }
00064             } else {
00065                 return e;
00066             }
00067         }
00068     }
00069 }

Generated on Sun Dec 25 12:14:33 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2