public static void fireFirstDeclared ( Throwable t , Class ... declaredTypes ) { Throwable cause = t ; while ( cause != null ) { cause = cause . getCause ( ) ; if ( cause == null ) { break ; } if ( declaredTypes != null ) { for ( Class declaredType : declaredTypes ) { if ( declaredType . isInstance ( cause ) ) { fire ( cause ) ; } } } if ( cause instanceof RuntimeException ) { throw ( RuntimeException ) cause ; } if ( cause instanceof Error ) { throw ( Error ) cause ; } } throw new UndeclaredThrowableException ( t ) ; }
Throws the either the original exception or the first found cause if it matches one of the given declared types or is unchecked . Otherwise the original exception is thrown as an UndeclaredThrowableException . This method only returns normally if the exception is null .