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!");
}
else if (t instanceof IllegalArgumentException)
{
// if mismatch between constructor instance args and supplied args -- shouldn't happen
throw new Error("Error in the server: mismatch between expected constructor arguments and supplied arguments.");
}
else if (t instanceof Error)
{
throw new RuntimeErrorException((Error)t, "instantiating " + className + " failed: " + t.toString());
}
}