@Test public void testFindThrowableByType() { assertTrue(ExceptionUtils.findThrowable( new RuntimeException(new IllegalStateException()), IllegalStateException.class).isPresent()); }
public static <T extends Throwable> Optional<T> findThrowable(Throwable throwable, Class<T> searchType) { if (throwable == null || searchType == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (searchType.isAssignableFrom(t.getClass())) { return Optional.of(searchType.cast(t)); } else { t = t.getCause(); } } return Optional.empty(); }
ExceptionUtils { public static <T extends Throwable> Optional<T> findThrowable(Throwable throwable, Class<T> searchType) { if (throwable == null || searchType == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (searchType.isAssignableFrom(t.getClass())) { return Optional.of(searchType.cast(t)); } else { t = t.getCause(); } } return Optional.empty(); } }
ExceptionUtils { public static <T extends Throwable> Optional<T> findThrowable(Throwable throwable, Class<T> searchType) { if (throwable == null || searchType == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (searchType.isAssignableFrom(t.getClass())) { return Optional.of(searchType.cast(t)); } else { t = t.getCause(); } } return Optional.empty(); } private  ExceptionUtils(); }
ExceptionUtils { public static <T extends Throwable> Optional<T> findThrowable(Throwable throwable, Class<T> searchType) { if (throwable == null || searchType == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (searchType.isAssignableFrom(t.getClass())) { return Optional.of(searchType.cast(t)); } else { t = t.getCause(); } } return Optional.empty(); } private  ExceptionUtils(); static String stringifyException(final Throwable e); static boolean isJvmFatalError(Throwable t); static boolean isJvmFatalOrOutOfMemoryError(Throwable t); static void rethrowIfFatalError(Throwable t); static void rethrowIfFatalErrorOrOOM(Throwable t); static T firstOrSuppressed(T newException, @Nullable T previous); static void rethrow(Throwable t); static void rethrow(Throwable t, String parentMessage); static void rethrowException(Throwable t, String parentMessage); static void rethrowException(Throwable t); static void tryRethrowException(@Nullable Exception e); static void tryRethrowIOException(Throwable t); static void rethrowIOException(Throwable t); static Optional<T> findThrowable(Throwable throwable, Class<T> searchType); static Optional<Throwable> findThrowable(Throwable throwable, Predicate<Throwable> predicate); static Optional<Throwable> findThrowableWithMessage(Throwable throwable, String searchMessage); static Throwable stripExecutionException(Throwable throwable); static Throwable stripCompletionException(Throwable throwable); static Throwable stripException(Throwable throwableToStrip, Class<? extends Throwable> typeToStrip); static void tryDeserializeAndThrow(Throwable throwable, ClassLoader classLoader); static void checkInterrupted(Throwable e); static void suppressExceptions(RunnableWithException action); }
ExceptionUtils { public static <T extends Throwable> Optional<T> findThrowable(Throwable throwable, Class<T> searchType) { if (throwable == null || searchType == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (searchType.isAssignableFrom(t.getClass())) { return Optional.of(searchType.cast(t)); } else { t = t.getCause(); } } return Optional.empty(); } private  ExceptionUtils(); static String stringifyException(final Throwable e); static boolean isJvmFatalError(Throwable t); static boolean isJvmFatalOrOutOfMemoryError(Throwable t); static void rethrowIfFatalError(Throwable t); static void rethrowIfFatalErrorOrOOM(Throwable t); static T firstOrSuppressed(T newException, @Nullable T previous); static void rethrow(Throwable t); static void rethrow(Throwable t, String parentMessage); static void rethrowException(Throwable t, String parentMessage); static void rethrowException(Throwable t); static void tryRethrowException(@Nullable Exception e); static void tryRethrowIOException(Throwable t); static void rethrowIOException(Throwable t); static Optional<T> findThrowable(Throwable throwable, Class<T> searchType); static Optional<Throwable> findThrowable(Throwable throwable, Predicate<Throwable> predicate); static Optional<Throwable> findThrowableWithMessage(Throwable throwable, String searchMessage); static Throwable stripExecutionException(Throwable throwable); static Throwable stripCompletionException(Throwable throwable); static Throwable stripException(Throwable throwableToStrip, Class<? extends Throwable> typeToStrip); static void tryDeserializeAndThrow(Throwable throwable, ClassLoader classLoader); static void checkInterrupted(Throwable e); static void suppressExceptions(RunnableWithException action); static final String STRINGIFIED_NULL_EXCEPTION; }