1 22 package org.jboss.mx.util; 23 24 import javax.management.*; 25 26 33 public class JMXExceptionDecoder 34 { 35 40 public static Throwable decode(final Throwable t) 41 { 42 Throwable result = t; 43 44 while (true) 45 { 46 if (result instanceof MBeanException) 47 result = ((MBeanException) result).getTargetException(); 48 else if (result instanceof ReflectionException) 49 result = ((ReflectionException) result).getTargetException(); 50 else if (result instanceof RuntimeOperationsException) 51 result = ((RuntimeOperationsException) result).getTargetException(); 52 else if (result instanceof RuntimeMBeanException) 53 result = ((RuntimeMBeanException) result).getTargetException(); 54 else if (result instanceof RuntimeErrorException) 55 result = ((RuntimeErrorException) result).getTargetError(); 56 else 57 break; 59 } 60 61 return result; 62 } 63 64 71 public static Throwable decodeToJMXException(final Throwable ex) 72 { 73 Throwable jmxEx = ex; 74 Throwable lastJmxEx = ex; 75 while( jmxEx instanceof JMException || jmxEx instanceof JMRuntimeException) 76 { 77 lastJmxEx = jmxEx; 78 jmxEx = decode(jmxEx); 79 if( jmxEx == lastJmxEx ) 80 break; 81 } 82 83 return lastJmxEx; 84 } 85 86 91 public static void rethrow(final Exception e) 92 throws Exception 93 { 94 Throwable t = decode(e); 95 if (t instanceof Exception ) 96 throw (Exception ) t; 97 else 98 throw (Error ) t; 99 } 100 } 101 | Popular Tags |