else if (t instanceof InvocationTargetException)
{
Throwable root = ((InvocationTargetException)t).getTargetException();
if (root instanceof RuntimeException)
throw new RuntimeMBeanException((RuntimeException)root, className + " constructor has thrown an exception: " + root.toString());
else if (root instanceof Error)
throw new RuntimeErrorException((Error)root, className + " constructor has thrown an error: " + root.toString());
else if (root instanceof Exception)
throw new MBeanException((Exception)root, className + " constructor has thrown an exception: " + root.toString());
throw new Error("Something went wrong with handling the exception from " + className + " default constructor.");
}
else if (t instanceof ExceptionInInitializerError)
{
Throwable root = ((ExceptionInInitializerError)t).getException();
// the root cause can be only a runtime exception
if (root instanceof RuntimeException)
throw new RuntimeMBeanException((RuntimeException)root, "Exception in class " + className + " static initializer: " + root.toString());
else
// shouldn't get here
throw new Error("ERROR: it turns out the root cause is not always a runtime exception!");
}