private static Throwable getExceptionCauseUsingMethodName ( final Throwable throwable , final CauseMethodName methodName ) { Method method = null ; try { method = throwable . getClass ( ) . getMethod ( methodName . toString ( ) , ( Class [ ] ) null ) ; } catch ( NoSuchMethodException exception ) { // NOPMD // Ignore (see Java Doc) } catch ( SecurityException exception ) { // NOPMD // Ignore (see Java Doc) } if ( method != null && Throwable . class . isAssignableFrom ( method . getReturnType ( ) ) ) { try { return ( Throwable ) method . invoke ( throwable , new Object [ ] { } ) ; } catch ( IllegalAccessException exception ) { // NOPMD // Ignore (see Java Doc) } catch ( IllegalArgumentException exception ) { // NOPMD // Ignore (see Java Doc) } catch ( InvocationTargetException exception ) { // NOPMD // Ignore (see Java Doc) } } return null ; }
To discover inner exception this method try to use reflection of known methods that could give the nested exception . So it ignore case of NoSuchMethodException SecurityException IllegalAccessException IllegalArgumentException and InvocationTargetException .