Class ExceptionUtil


  • @Scriptable
    public final class ExceptionUtil
    extends Object
    • Method Detail

      • isCausedBy

        public static boolean isCausedBy​(Throwable p_e,
                                         String p_strExceptionClass)
                                  throws ClassNotFoundException
        Check if the given exception is caused by an exception of the given type.
        Parameters:
        p_e - The exception.
        p_strExceptionClass - The type of the exception.
        Returns:
        true if the given exception is caused by an exception of the given type, or false otherwise.
        Throws:
        ClassNotFoundException - - If p_strExceptionClass is not found.
        See Also:
        getCauseOfType(Throwable, String)
      • isCausedBy

        public static boolean isCausedBy​(Throwable p_e,
                                         Class<? extends Throwable> p_clsException)
        Check if the given exception is caused by an exception of the given type.
        Parameters:
        p_e - The exception.
        p_clsException - The type of the exception.
        Returns:
        true if the given exception is caused by an exception of the given type, or false otherwise.
        See Also:
        getCauseOfType(Throwable, Class)
      • getCauseOfType

        public static Throwable getCauseOfType​(Throwable p_e,
                                               String p_strExceptionClass)
                                        throws ClassNotFoundException
        Get the first cause of the given type.
        Parameters:
        p_e - The exception.
        p_strExceptionClass - The type of the exception.
        Returns:
        The first cause of the exception of the given type, or null if no such cause could be found.
        Throws:
        ClassNotFoundException - - If p_strExceptionClass is not found.
      • getCauseOfType

        public static <T extends Throwable> T getCauseOfType​(Throwable p_e,
                                                             Class<T> p_clsException)
        Get the first cause of the given type.
        Parameters:
        p_e - The exception.
        p_clsException - The type of the exception.
        Returns:
        The first cause of the exception of the given type, or null if no such cause could be found.
      • isCausedByAccessControlException

        public static boolean isCausedByAccessControlException​(Throwable p_e)
        Check if the given exception is caused by a java.security.AccessControlException.
        Returns:
        true if the give exception is caused by a java.security.AccessControlException, or false otherwise.
      • getRootCause

        public static Throwable getRootCause​(Throwable p_e)
        Get the root cause of an exception.
        Parameters:
        p_e - The exception.
        Returns:
        The root cause, or p_e if no cause exists.
      • prefixMessage

        public static <T extends Throwable> T prefixMessage​(T p_e,
                                                            String p_strPrefix)
        Try to prefix the given exception's message with the given prefix.

        Under normal circumstances exceptions should be wrapped as the cause of newly thrown exceptions. So use this method sparingly.

        Parameters:
        p_e - The exception.
        p_strPrefix - The prefix.
        Returns:
        p_e with a prefixed message.
      • getStackTrace

        public static String getStackTrace​(Throwable p_e)
        Get the stack trace of the given exception as a string.
        Parameters:
        p_e - The exception.
        Returns:
        The stack trace.