| 1 20 package net.sf.clirr.core.internal; 21 22 import java.lang.reflect.Method ; 23 24 33 public final class ExceptionUtil 34 { 35 36 private ExceptionUtil() 37 { 38 } 39 40 private static Method initCauseMethod; 41 42 static 43 { 44 try 45 { 46 initCauseMethod = Throwable .class.getMethod("initCause", new Class []{Throwable .class}); 47 } 48 catch (NoSuchMethodException e) 49 { 50 initCauseMethod = null; 52 } 53 } 54 55 63 public static void initCause(Throwable t, Throwable cause) 64 { 65 if (initCauseMethod == null) 66 { 67 return; 68 } 69 70 try 71 { 72 initCauseMethod.invoke(t, new Throwable []{cause}); 73 } 74 catch (Exception e) 75 { 76 if (e instanceof RuntimeException ) 77 { 78 throw (RuntimeException ) e; 79 } 80 throw new RuntimeException ("unable to initCause: " + e.toString()); 81 } 82 } 83 } 84 | Popular Tags |