Code example for InvocationTargetException

Methods: getCause

0
 
        try { 
            sMethodRegisterMediaButtonEventReceiver.invoke(audioManager, receiver);
        } catch (InvocationTargetException e) {
            // Unpack original exception when possible 
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            } else if (cause instanceof Error) {
                throw (Error) cause;
            } else { 
                // Unexpected checked exception; wrap and re-throw 
                throw new RuntimeException(e);
            } 
        } catch (IllegalAccessException e) {
            Log.e(TAG, "IllegalAccessException invoking registerMediaButtonEventReceiver.");
            e.printStackTrace();
        } 
    } 
 
    public static void unregisterMediaButtonEventReceiverCompat(AudioManager audioManager,