1 22 package org.jboss.mx.server; 23 24 26 import javax.management.*; 27 28 33 public class ExceptionHandler 34 { 35 36 private ExceptionHandler() 38 { 39 } 40 41 47 public static JMException handleException(Throwable t) 48 { 49 handleRuntimeExceptionOrError(t); 50 51 Exception e = (Exception )t; 53 54 if (e instanceof OperationsException) 55 return (OperationsException)e; 56 if (e instanceof ReflectionException) 57 return (ReflectionException)e; 58 if (e instanceof MBeanRegistrationException) 59 return (MBeanRegistrationException)e; 60 61 if (e instanceof ClassNotFoundException ) 63 return new ReflectionException(e); 64 if (e instanceof IllegalAccessException ) 65 return new ReflectionException(e); 66 if (e instanceof InstantiationException ) 67 return new ReflectionException(e); 68 if (e instanceof NoSuchMethodException ) 69 return new ReflectionException(e); 70 71 if (e instanceof MBeanException) 74 { 75 Throwable cause = e.getCause(); 76 77 if (cause instanceof JMException) 78 return (JMException)cause; 79 else 80 return (MBeanException)e; 81 } 82 83 return new MBeanException(e); 85 } 86 87 92 private static void handleRuntimeExceptionOrError(Throwable e) 93 { 94 if (e instanceof RuntimeOperationsException) 96 throw (RuntimeOperationsException)e; 97 if (e instanceof RuntimeErrorException) 98 throw (RuntimeErrorException)e; 99 if (e instanceof RuntimeMBeanException) 100 throw (RuntimeMBeanException)e; 101 102 if (e instanceof IllegalArgumentException ) 104 throw new RuntimeOperationsException((IllegalArgumentException )e); 105 if (e instanceof IndexOutOfBoundsException ) 106 throw new RuntimeOperationsException((IndexOutOfBoundsException )e); 107 if (e instanceof NullPointerException ) 108 throw new RuntimeOperationsException((NullPointerException )e); 109 110 if (e instanceof Error ) 112 throw new RuntimeErrorException((Error )e); 113 114 if (e instanceof RuntimeException ) 116 throw new RuntimeMBeanException((RuntimeException )e); 117 } 118 119 } 120 | Popular Tags |