/** * Checks if passed in {@code 'Throwable'} has given class in {@code 'cause'} hierarchy * <b>including</b> that throwable itself. * <p> * Note that this method follows includes {@link Throwable#getSuppressed()} * into check. * * @param cls Cause classes to check (if {@code null} or empty, {@code false} is returned). * @return {@code True} if one of the causing exception is an instance of passed in classes, * {@code false} otherwise. */ public boolean hasCause(@Nullable Class<? extends Throwable>... cls) { return hasCause(this, cls); }
/** * Checks if passed in {@code 'Throwable'} has given class in {@code 'cause'} hierarchy * <b>including</b> that throwable itself. * <p> * Note that this method follows includes {@link Throwable#getSuppressed()} * into check. * * @param t Throwable to check (if {@code null}, {@code false} is returned). * @param cls Cause classes to check (if {@code null} or empty, {@code false} is returned). * @return {@code True} if one of the causing exception is an instance of passed in classes, * {@code false} otherwise. */ private boolean hasCause(@Nullable Throwable t, @Nullable Class<? extends Throwable>... cls) { if (t == null || F.isEmpty(cls)) return false; assert cls != null; for (Throwable th = t; th != null; th = th.getCause()) { for (Class<? extends Throwable> c : cls) if (c.isAssignableFrom(th.getClass())) return true; for (Throwable n : th.getSuppressed()) if (hasCause(n, cls)) return true; if (th.getCause() == th) break; } return false; }
/** * Checks if passed in {@code 'Throwable'} has given class in {@code 'cause'} hierarchy * <b>including</b> that throwable itself. * <p> * Note that this method follows includes {@link Throwable#getSuppressed()} * into check. * * @param cls Cause classes to check (if {@code null} or empty, {@code false} is returned). * @return {@code True} if one of the causing exception is an instance of passed in classes, * {@code false} otherwise. */ public boolean hasCause(@Nullable Class<? extends Throwable>... cls) { return hasCause(this, cls); }
/** * Checks if passed in {@code 'Throwable'} has given class in {@code 'cause'} hierarchy * <b>including</b> that throwable itself. * <p> * Note that this method follows includes {@link Throwable#getSuppressed()} * into check. * * @param t Throwable to check (if {@code null}, {@code false} is returned). * @param cls Cause classes to check (if {@code null} or empty, {@code false} is returned). * @return {@code True} if one of the causing exception is an instance of passed in classes, * {@code false} otherwise. */ private boolean hasCause(@Nullable Throwable t, @Nullable Class<? extends Throwable>... cls) { if (t == null || F.isEmpty(cls)) return false; assert cls != null; for (Throwable th = t; th != null; th = th.getCause()) { for (Class<? extends Throwable> c : cls) if (c.isAssignableFrom(th.getClass())) return true; for (Throwable n : th.getSuppressed()) if (hasCause(n, cls)) return true; if (th.getCause() == th) break; } return false; }