public static < T extends Throwable > RuntimeException rethrowAllowedTypeFirst ( final Throwable t , Class < T > allowedType ) throws T { rethrowIfError ( t ) ; if ( allowedType . isAssignableFrom ( t . getClass ( ) ) ) { throw ( T ) t ; } else { throw peel ( t ) ; } }
This rethrow the exception providing an allowed Exception in first priority even it is a Runtime exception