Class ApplicationException

All Implemented Interfaces:
TopLevelException, Serializable

public class ApplicationException extends RuntimeException implements TopLevelException
Class for Exceptions thrown in @enterprise and applications. The class has several constructors. One set has an error number as first parameter. Use these constructors for throwing numbered @enterprise exceptions. The second set has a String as first parameter. Use these constructors for throwing an exception defined in the application. If your application uses internationalization, you can write <application-id>:<resource-key> for using the strings from the application resource bundle.
See Also:
  • Field Details

  • Constructor Details

    • ApplicationException

      public ApplicationException(int errnum)
      Construct an ApplicationException with an exception number.
      Parameters:
      errnum - the key in the enterprise errors resource
    • ApplicationException

      public ApplicationException(int errnum, ApplicationException.Level level)
      Construct an ApplicationException with an exception number.
      Parameters:
      errnum - the key in the enterprise errors resource
      level - level for logging the exception, default is ERROR
    • ApplicationException

      public ApplicationException(int errnum, Object[] args)
      Construct an ApplicationException with an exception number and args
      Parameters:
      errnum - the key in the given resource
      args - message-format arguments
    • ApplicationException

      public ApplicationException(int errnum, Object[] args, Throwable cause)
      Construct an ApplicationException with an exception number, args and the cause exception.
      Parameters:
      errnum - the key in the given resource
      args - message-format arguments
      cause - the causing exception
    • ApplicationException

      public ApplicationException(int errnum, Object[] args, Throwable cause, ApplicationException.Level level)
      Construct an ApplicationException with an exception number, args and the cause exception.
      Parameters:
      errnum - the key in the given resource
      args - message-format arguments
      cause - the causing exception
      level - level for logging the exception, default is ERROR
    • ApplicationException

      public ApplicationException(int errnum, Throwable cause)
      Construct an ApplicationException with an exception number and the cause exception.
      Parameters:
      errnum - the key in the given resource
      cause - the causing exception
    • ApplicationException

      public ApplicationException(String message)
      Construct an ApplicationException with a message.
      Parameters:
      message - the error message
    • ApplicationException

      public ApplicationException(String message, Throwable cause)
      Construct an ApplicationException with a message and the cause exception.
      Parameters:
      message - the error message
      cause - the causing exception
    • ApplicationException

      public ApplicationException(String message, ApplicationException.Level level)
      Construct an ApplicationException with a message and the cause exception.
      Parameters:
      message - the error message
      level - level for logging the exception, default is ERROR
    • ApplicationException

      public ApplicationException(String message, Object[] args)
      Construct an ApplicationException with a message and the cause exception.
      Parameters:
      message - the error message
      args - message-format arguments
    • ApplicationException

      public ApplicationException(String message, Object[] args, Throwable cause)
      Construct an ApplicationException with a message and the cause exception.
      Parameters:
      message - the error message
      args - message-format arguments
      cause - the causing exception
    • ApplicationException

      public ApplicationException(String message, Throwable cause, ApplicationException.Level level)
      Construct an ApplicationException with a message and the cause exception.
      Parameters:
      message - the error message
      cause - the causing exception
      level - level for logging the exception, default is ERROR
    • ApplicationException

      public ApplicationException(String message, Object[] args, Throwable cause, ApplicationException.Level level)
      Construct an ApplicationException with a message and the cause exception.
      Parameters:
      message - the error message
      args - message-format arguments
      cause - the causing exception
      level - level for logging the exception, default is ERROR
    • ApplicationException

      public ApplicationException(Throwable cause)
      Construct an ApplicationException with a cause exception.
      Parameters:
      cause - the causing exception
    • ApplicationException

      @Deprecated(since="11.0", forRemoval=true) public ApplicationException(Resource resource, int errnum)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use constructor with string as first argument
      Construct an ApplicationException with an exception number and a resource.
      Parameters:
      resource - a resource containing the error messages.
      errnum - the key in the given resource
    • ApplicationException

      @Deprecated(since="11.0", forRemoval=true) public ApplicationException(Resource resource, int errnum, Object[] args)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use constructor with string as first argument
      Construct an ApplicationException with a resource, exception number and args.
      Parameters:
      resource - a resource containing the error messages
      errnum - the key in the given resource
      args - message-format arguments
    • ApplicationException

      @Deprecated(since="11.0", forRemoval=true) public ApplicationException(Resource resource, int errnum, Object[] args, Throwable cause)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use constructor with string as first argument
      Construct an ApplicationException with a resource, exception number, args and the cause exception.
      Parameters:
      resource - a resource containing the error messages
      errnum - the key in the given resource
      args - message-format arguments
      cause - the causing exception
    • ApplicationException

      @Deprecated(since="11.0", forRemoval=true) public ApplicationException(Resource resource, int errnum, Throwable cause)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use constructor with string as first argument
      Construct an ApplicationException with a resource, exception number, and the cause exception.
      Parameters:
      resource - a resource containing the error messages
      errnum - the key in the given resource
      cause - the causing exception
    • ApplicationException

      @Deprecated(since="9.0", forRemoval=true) public ApplicationException(int errnum, String msg, Throwable cause)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Don't use this signature, use placeholders and an argument array.
      Construct an ApplicationException with an exception number, an extra message and the cause exception.
      Parameters:
      errnum - the key in the given resource
      msg - text that is added to the message from the error resource.
      cause - the causing exception
    • ApplicationException

      @Deprecated(since="9.0", forRemoval=true) public ApplicationException(Resource resource, int errnum, String msg, Throwable cause)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Don't use this signature, use placeholders and an argument array.
      Construct an ApplicationException with a resource, an exception number, an extra message and the cause exception.
      Parameters:
      resource - a resource containing the error messages
      errnum - the key in the given resource
      msg - text that is added to the message from the error resource.
      cause - the causing exception
  • Method Details

    • wrap

      public static ApplicationException wrap(Throwable cause)
      Conditionally wrap an exception. If the cause is already an ApplicationException, it is returned directly without any further wrapping. All other types of causes result in a new ApplicationException which is wrapping the cause.
      Parameters:
      cause - the causing Exception
      Returns:
      the potentially wrapped ApplicationException
    • getArgs

      public Object[] getArgs()
    • getErrnum

      public int getErrnum()
      Returns the error number, 0 if none specified.
      Specified by:
      getErrnum in interface TopLevelException
    • getKey

      public String getKey()
      Returns the key of the exception. This is either the error number or the error string, depending on the constructor used.
    • getErrorFormatter

      public ErrorFormatter getErrorFormatter()
      Returns the error formatter for this exception. If none is set, the method return null and the default ErrorFormatter defined in the system configuration will be used. If none is defined, DefaultErrorFormatter is used.
      Returns:
      the error formatter set for this exception.
    • getMessage

      public String getMessage()
      Returns message text including title.
      Overrides:
      getMessage in class Throwable
    • getMessageText

      public String getMessageText()
      Returns the plain message text without "Error" prefix and number.
    • log

      protected void log(String marker, ApplicationException.Level level, org.slf4j.Logger logger)
      Log the exception using the given level and logger.
    • setErrorFormatter

      public void setErrorFormatter(ErrorFormatter ef)
      Set the formatter for formatting the error page.
      Parameters:
      ef -
    • allowHTMLMessage

      public boolean allowHTMLMessage()
    • setAllowHTMLMessage

      public void setAllowHTMLMessage(boolean allowHTMLMessage)
      set to true to allow html-formatted error-messages, false by default
      Parameters:
      allowHTMLMessage -
    • setTitle

      public ApplicationException setTitle(String title)
      Set the title of the error-message on client-side.
      Parameters:
      title - string
    • getTitle

      public String getTitle()
      Get the title used for the error-message on client side.
      Returns:
      title string
    • getLevel

      public ApplicationException.Level getLevel()
      Return the log level of this exception.
      Specified by:
      getLevel in interface TopLevelException
    • getException

      @Deprecated(since="11.0", forRemoval=true) public Throwable getException()
      Deprecated, for removal: This API element is subject to removal in a future version.
      use getCause()
      Description copied from interface: TopLevelException
      Returns an inner exception, null if there is none.
      Specified by:
      getException in interface TopLevelException
    • setWarning

      @Deprecated(since="11.0", forRemoval=true) public void setWarning(boolean warning)
      Deprecated, for removal: This API element is subject to removal in a future version.
      set level ApplicationException.Level.WARN via constructor - or use another ApplicationException.Level to mark your exception differently
      Set the exception type to warning. This can be interpreted in the GUI to show the error message differently.
      Specified by:
      setWarning in interface TopLevelException
    • isWarning

      @Deprecated(since="11.0", forRemoval=true) public boolean isWarning()
      Deprecated, for removal: This API element is subject to removal in a future version.
      check for level ApplicationException.Level.WARN returned by getLevel() instead
      Specified by:
      isWarning in interface TopLevelException