Package com.groiss.util
Class ApplicationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.groiss.util.ApplicationException
- All Implemented Interfaces:
TopLevelException
,Serializable
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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Level for logging the exception. -
Field Summary
Modifier and TypeFieldDescriptionprotected final String
The text of the messageprotected boolean
protected final Object[]
protected ErrorFormatter
static final String
protected final int
protected boolean
Deprecated, for removal: This API element is subject to removal in a future version.protected final ApplicationException.Level
log level for exception loggingprotected String
static final String
-
Constructor Summary
ConstructorDescriptionApplicationException
(int errnum) Construct an ApplicationException with an exception number.ApplicationException
(int errnum, ApplicationException.Level level) Construct an ApplicationException with an exception number.ApplicationException
(int errnum, Object[] args) Construct an ApplicationException with an exception number and argsApplicationException
(int errnum, Object[] args, Throwable cause) Construct an ApplicationException with an exception number, args and the cause exception.ApplicationException
(int errnum, Object[] args, Throwable cause, ApplicationException.Level level) Construct an ApplicationException with an exception number, args and the cause exception.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.ApplicationException
(int errnum, Throwable cause) Construct an ApplicationException with an exception number and the cause exception.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 argumentApplicationException
(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 argumentApplicationException
(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 argumentApplicationException
(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.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 argumentApplicationException
(String message) Construct an ApplicationException with a message.ApplicationException
(String message, ApplicationException.Level level) Construct an ApplicationException with a message and the cause exception.ApplicationException
(String message, Object[] args) Construct an ApplicationException with a message and the cause exception.ApplicationException
(String message, Object[] args, Throwable cause) Construct an ApplicationException with a message and the cause exception.ApplicationException
(String message, Object[] args, Throwable cause, ApplicationException.Level level) Construct an ApplicationException with a message and the cause exception.ApplicationException
(String message, Throwable cause) Construct an ApplicationException with a message and the cause exception.ApplicationException
(String message, Throwable cause, ApplicationException.Level level) Construct an ApplicationException with a message and the cause exception.ApplicationException
(Throwable cause) Construct an ApplicationException with a cause exception. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Object[]
getArgs()
int
Returns the error number, 0 if none specified.Returns the error formatter for this exception.Deprecated, for removal: This API element is subject to removal in a future version.use getCause()getKey()
Returns the key of the exception.getLevel()
Return the log level of this exception.Returns message text including title.Returns the plain message text without "Error" prefix and number.getTitle()
Get the title used for the error-message on client side.boolean
Deprecated, for removal: This API element is subject to removal in a future version.check for levelApplicationException.Level.WARN
returned bygetLevel()
insteadprotected void
log
(String marker, ApplicationException.Level level, org.slf4j.Logger logger) Log the exception using the given level and logger.void
setAllowHTMLMessage
(boolean allowHTMLMessage) set totrue
to allow html-formatted error-messages,false
by defaultvoid
Set the formatter for formatting the error page.Set the title of the error-message on client-side.void
setWarning
(boolean warning) Deprecated, for removal: This API element is subject to removal in a future version.set levelApplicationException.Level.WARN
via constructor - or use anotherApplicationException.Level
to mark your exception differentlystatic ApplicationException
Conditionally wrap an exception.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
EXCEPTION_MARKER
- See Also:
-
WRAPPER_MARKER
- See Also:
-
ef
-
title
-
allowHTMLMessage
protected boolean allowHTMLMessage -
exceptionNumber
protected final int exceptionNumber -
arguments
-
addText
The text of the message -
logLevel
log level for exception logging -
isWarning
Deprecated, for removal: This API element is subject to removal in a future version.use levelApplicationException.Level.WARN
via constructor instead
-
-
Constructor Details
-
ApplicationException
public ApplicationException(int errnum) Construct an ApplicationException with an exception number.- Parameters:
errnum
- the key in the enterprise errors resource
-
ApplicationException
Construct an ApplicationException with an exception number.- Parameters:
errnum
- the key in the enterprise errors resourcelevel
- level for logging the exception, default is ERROR
-
ApplicationException
Construct an ApplicationException with an exception number and args- Parameters:
errnum
- the key in the given resourceargs
- message-format arguments
-
ApplicationException
Construct an ApplicationException with an exception number, args and the cause exception.- Parameters:
errnum
- the key in the given resourceargs
- message-format argumentscause
- 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 resourceargs
- message-format argumentscause
- the causing exceptionlevel
- level for logging the exception, default is ERROR
-
ApplicationException
Construct an ApplicationException with an exception number and the cause exception.- Parameters:
errnum
- the key in the given resourcecause
- the causing exception
-
ApplicationException
Construct an ApplicationException with a message.- Parameters:
message
- the error message
-
ApplicationException
Construct an ApplicationException with a message and the cause exception.- Parameters:
message
- the error messagecause
- the causing exception
-
ApplicationException
Construct an ApplicationException with a message and the cause exception.- Parameters:
message
- the error messagelevel
- level for logging the exception, default is ERROR
-
ApplicationException
Construct an ApplicationException with a message and the cause exception.- Parameters:
message
- the error messageargs
- message-format arguments
-
ApplicationException
Construct an ApplicationException with a message and the cause exception.- Parameters:
message
- the error messageargs
- message-format argumentscause
- the causing exception
-
ApplicationException
Construct an ApplicationException with a message and the cause exception.- Parameters:
message
- the error messagecause
- the causing exceptionlevel
- 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 messageargs
- message-format argumentscause
- the causing exceptionlevel
- level for logging the exception, default is ERROR
-
ApplicationException
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 argumentConstruct 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 argumentConstruct an ApplicationException with a resource, exception number and args.- Parameters:
resource
- a resource containing the error messageserrnum
- the key in the given resourceargs
- 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 argumentConstruct an ApplicationException with a resource, exception number, args and the cause exception.- Parameters:
resource
- a resource containing the error messageserrnum
- the key in the given resourceargs
- message-format argumentscause
- 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 argumentConstruct an ApplicationException with a resource, exception number, and the cause exception.- Parameters:
resource
- a resource containing the error messageserrnum
- the key in the given resourcecause
- 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 resourcemsg
- 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 messageserrnum
- the key in the given resourcemsg
- text that is added to the message from the error resource.cause
- the causing exception
-
-
Method Details
-
wrap
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
-
getErrnum
public int getErrnum()Returns the error number, 0 if none specified.- Specified by:
getErrnum
in interfaceTopLevelException
-
getKey
Returns the key of the exception. This is either the error number or the error string, depending on the constructor used. -
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
Returns message text including title.- Overrides:
getMessage
in classThrowable
-
getMessageText
Returns the plain message text without "Error" prefix and number. -
log
Log the exception using the given level and logger. -
setErrorFormatter
Set the formatter for formatting the error page.- Parameters:
ef
-
-
allowHTMLMessage
public boolean allowHTMLMessage() -
setAllowHTMLMessage
public void setAllowHTMLMessage(boolean allowHTMLMessage) set totrue
to allow html-formatted error-messages,false
by default- Parameters:
allowHTMLMessage
-
-
setTitle
Set the title of the error-message on client-side.- Parameters:
title
- string
-
getTitle
Get the title used for the error-message on client side.- Returns:
- title string
-
getLevel
Return the log level of this exception.- Specified by:
getLevel
in interfaceTopLevelException
-
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 interfaceTopLevelException
-
setWarning
Deprecated, for removal: This API element is subject to removal in a future version.set levelApplicationException.Level.WARN
via constructor - or use anotherApplicationException.Level
to mark your exception differentlySet the exception type to warning. This can be interpreted in the GUI to show the error message differently.- Specified by:
setWarning
in interfaceTopLevelException
-
isWarning
Deprecated, for removal: This API element is subject to removal in a future version.check for levelApplicationException.Level.WARN
returned bygetLevel()
instead- Specified by:
isWarning
in interfaceTopLevelException
-
ApplicationException.Level.WARN
via constructor instead