public static void rethrowException(Throwable ex) throws Exception {
        if (ex instanceof Exception) {
            throw (Exception) ex;
        }
        if (ex instanceof Error) {
            throw (Error) ex;
        }
        throw new UndeclaredThrowableException(ex);
    }
Rethrow the given {@link Throwable exception}, which is presumably the
<em>target exception</em> of an {@link InvocationTargetException}.
Should only be called if no checked exception is expected to be thrown
by the target method.
<p>Rethrows the underlying exception cast to an {@link Exception} or
{@link Error} if appropriate; otherwise, throws an {@link IllegalStateException}.

@param ex the exception to rethrow
@throws Exception the rethrown exception (in case of a checked exception)
android/android_framework/base/src/main/java/util/ReflectionUtils.java