1 8 9 package com.sleepycat.util; 10 11 19 public class ExceptionUnwrapper { 20 21 34 public static Exception unwrap(Exception e) { 35 36 Throwable t = unwrapAny(e); 37 if (t instanceof Exception ) { 38 return (Exception ) t; 39 } else if (t instanceof Error ) { 40 throw (Error ) t; 41 } else { 42 throw new IllegalArgumentException ("Not Exception or Error: " + t); 43 } 44 } 45 46 53 public static Throwable unwrapAny(Throwable e) { 54 55 while (true) { 56 if (e instanceof ExceptionWrapper) { 57 Throwable e2 = ((ExceptionWrapper) e).getCause(); 58 if (e2 == null) { 59 return e; 60 } else { 61 e = e2; 62 } 63 } else { 64 return e; 65 } 66 } 67 } 68 } 69 | Popular Tags |