Class ExceptionConverter

All Implemented Interfaces:
Serializable

public class ExceptionConverter extends RuntimeException
The ExceptionConverter changes a checked exception into an unchecked exception.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • ex

      private Exception ex
      we keep a handle to the wrapped exception
    • prefix

      private String prefix
      prefix for the exception
  • Constructor Details

    • ExceptionConverter

      public ExceptionConverter(Exception ex)
      Construct a RuntimeException based on another Exception
      Parameters:
      ex - the exception that has to be turned into a RuntimeException
  • Method Details

    • convertException

      public static final RuntimeException convertException(Exception ex)
      Convert an Exception into an unchecked exception. Return the exception if it is already an unchecked exception or return an ExceptionConverter wrapper otherwise
      Parameters:
      ex - the exception to convert
      Returns:
      an unchecked exception
      Since:
      2.1.6
    • getException

      public Exception getException()
      and allow the user of ExceptionConverter to get a handle to it.
      Returns:
      the original exception
    • getMessage

      public String getMessage()
      We print the message of the checked exception
      Overrides:
      getMessage in class Throwable
      Returns:
      message of the original exception
    • getLocalizedMessage

      public String getLocalizedMessage()
      and make sure we also produce a localized version
      Overrides:
      getLocalizedMessage in class Throwable
      Returns:
      localized version of the message
    • toString

      public String toString()
      The toString() is changed to be prefixed with ExceptionConverter
      Overrides:
      toString in class Throwable
      Returns:
      String version of the exception
    • printStackTrace

      public void printStackTrace()
      we have to override this as well
      Overrides:
      printStackTrace in class Throwable
    • printStackTrace

      public void printStackTrace(PrintStream printStream)
      here we prefix, with printStream.print(), not printStream.println(), the stack trace with "ExceptionConverter:"
      Overrides:
      printStackTrace in class Throwable
      Parameters:
      printStream - printStream
    • printStackTrace

      public void printStackTrace(PrintWriter printWriter)
      Again, we prefix the stack trace with "ExceptionConverter:"
      Overrides:
      printStackTrace in class Throwable
      Parameters:
      printWriter - printWriter
    • fillInStackTrace

      public Throwable fillInStackTrace()
      requests to fill in the stack trace we will have to ignore. We can't throw an exception here, because this method is called by the constructor of Throwable
      Overrides:
      fillInStackTrace in class Throwable
      Returns:
      a Throwable