public static void handleReflectionException(Exception ex) {
        if (ex instanceof NoSuchMethodException) {
            throw new IllegalStateException("Method not found: " + ex.getMessage());
        }
        if (ex instanceof IllegalAccessException) {
            throw new IllegalStateException("Could not access method: " + ex.getMessage());
        }
        if (ex instanceof InvocationTargetException) {
            handleInvocationTargetException((InvocationTargetException) ex);
        }
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        }
        throw new UndeclaredThrowableException(ex);
    }
Handle the given reflection exception. Should only be called if no
checked exception is expected to be thrown by the target method.
<p>Throws the underlying RuntimeException or Error in case of an
InvocationTargetException global such a root cause. Throws an
IllegalStateException global an appropriate message else.

@param ex the reflection exception to handle
android/android_framework/base/src/main/java/util/ReflectionUtils.java