Class ExceptionUtil


  • public final class ExceptionUtil
    extends java.lang.Object
    Exception utility
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ExceptionUtil getInstance()
      Get the instance
      java.lang.String prepareExceptionWithStacktraceInMessage​(java.lang.Exception ex)
      Prepare the exception message
      java.lang.String prepareStacktraceInMessage​(java.lang.Exception ex, java.lang.String filterPackage)
      Throws a defined exception
      <E extends java.lang.Exception>
      E
      throwExceptionWithStacktraceInMessage​(java.lang.Exception ex, java.lang.Class<E> exceptionClass)
      Throws a defined exception
      <E extends java.lang.Exception>
      E
      throwExceptionWithStacktraceInMessage​(java.lang.Exception ex, java.lang.Class<E> exceptionClass, java.lang.String filterPackage)
      Throws a defined exception
      <E extends java.lang.Exception>
      E
      throwsException​(java.lang.Class<E> exceptionClass, java.lang.String message)
      Throws an exception with a specific message
      <E extends java.lang.Exception>
      E
      throwsException​(java.lang.Class<E> exceptionClass, java.lang.String message, java.lang.StackTraceElement[] stackTraceElement)
      Throws an exception with a specific message
      <E extends java.lang.Exception>
      E
      throwsException​(java.lang.Exception ex, java.lang.Class<E> exceptionClass, boolean withStacktrace)
      Throws an exception with a specific message
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInstance

        public static ExceptionUtil getInstance()
        Get the instance
        Returns:
        the instance
      • prepareExceptionWithStacktraceInMessage

        public java.lang.String prepareExceptionWithStacktraceInMessage​(java.lang.Exception ex)
        Prepare the exception message
        Parameters:
        ex - the exception
        Returns:
        the message
      • prepareStacktraceInMessage

        public java.lang.String prepareStacktraceInMessage​(java.lang.Exception ex,
                                                           java.lang.String filterPackage)
        Throws a defined exception
        Parameters:
        ex - the exception
        filterPackage - the package filter
        Returns:
        the message
      • throwExceptionWithStacktraceInMessage

        public <E extends java.lang.Exception> E throwExceptionWithStacktraceInMessage​(java.lang.Exception ex,
                                                                                       java.lang.Class<E> exceptionClass)
        Throws a defined exception
        Type Parameters:
        E - the exception type
        Parameters:
        ex - the exception
        exceptionClass - the new exception class
        Returns:
        the exception
      • throwExceptionWithStacktraceInMessage

        public <E extends java.lang.Exception> E throwExceptionWithStacktraceInMessage​(java.lang.Exception ex,
                                                                                       java.lang.Class<E> exceptionClass,
                                                                                       java.lang.String filterPackage)
        Throws a defined exception
        Type Parameters:
        E - the exception type
        Parameters:
        ex - the exception
        exceptionClass - the new exception class
        filterPackage - the package filter
        Returns:
        the exception
      • throwsException

        public <E extends java.lang.Exception> E throwsException​(java.lang.Exception ex,
                                                                 java.lang.Class<E> exceptionClass,
                                                                 boolean withStacktrace)
        Throws an exception with a specific message
        Type Parameters:
        E - the exception type
        Parameters:
        ex - the exception
        exceptionClass - the exception class
        withStacktrace - true to add the stacktrace
        Returns:
        the exception
        Throws:
        java.lang.IllegalStateException - In case of an invalid state
      • throwsException

        public <E extends java.lang.Exception> E throwsException​(java.lang.Class<E> exceptionClass,
                                                                 java.lang.String message)
        Throws an exception with a specific message
        Type Parameters:
        E - the exception type
        Parameters:
        exceptionClass - the exception class
        message - the message
        Returns:
        the exception
        Throws:
        java.lang.IllegalArgumentException - In case of an invalid state
      • throwsException

        public <E extends java.lang.Exception> E throwsException​(java.lang.Class<E> exceptionClass,
                                                                 java.lang.String message,
                                                                 java.lang.StackTraceElement[] stackTraceElement)
        Throws an exception with a specific message
        Type Parameters:
        E - the exception type
        Parameters:
        exceptionClass - the exception class
        message - the message
        stackTraceElement - the stacktrace element
        Returns:
        the exception
        Throws:
        java.lang.IllegalArgumentException - In case of an invalid state