Class ErrorUtils


  • public final class ErrorUtils
    extends Object
    Utilities for working with Exceptions.
    • Method Detail

      • stackTrace

        public static String stackTrace​(Throwable error)
        Returns stackt race as string.
        Parameters:
        error - Error.
        Returns:
        Stack trace as a string.
      • isCausedBy

        public static boolean isCausedBy​(Class<? extends Throwable> type,
                                         Throwable error)
        Returns true if the specified exception is an error of the specified type or is caused by an error of the specified type.

        This method recursively scans the whole cause tree unless an error the specified type is found the bottom of the tree is reached.

        Parameters:
        type - Error type to check for.
        error - Error (can be null).
        Returns:
        true if the specified exception is an error of the specified type or is caused by an error of the specified type.
      • findCause

        public static <T extends Throwable> T findCause​(Class<T> type,
                                                        Throwable error)
        Returns an error instance of the specified type by scanning the cause tree.
        Type Parameters:
        T - Error type to search for.
        Parameters:
        type - Error type to search for.
        error - Error (can be null).
        Returns:
        Error or null if the specified error is not of the specified type and is not caused by an error of the specified type.