- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- io.github.mmm.base.exception.ApplicationException
-
- All Implemented Interfaces:
Localizable,LocalizableObject,Serializable
- Direct Known Subclasses:
CliException,DuplicateObjectException,ObjectMismatchException,ObjectNotFoundException,ReadOnlyException,RuntimeIoException,TechnicalErrorUserException
public abstract class ApplicationException extends RuntimeException implements Localizable
ExtendsRuntimeExceptionwith the following features:- a
UUIDunique per exception instance automatically generated once per exceptionchain. - an
error codethat should be unique per exception type. - distinction between
technicalexceptions and exceptionsintended for end-users.
Exceptions should only occur in unexpected or undesired situations. Never use exceptions for control flows.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description ApplicationException(Localizable message)The constructor.ApplicationException(Localizable message, Throwable cause)The constructor.protectedApplicationException(Localizable message, Throwable cause, UUID uuid)The constructor.ApplicationException(String message)The constructor.ApplicationException(String message, Throwable cause)The constructor.protectedApplicationException(String message, Throwable cause, UUID uuid)The constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected UUIDcreateUuid()StringgetCode()This method gets the code that identifies the detailed type of this object.StringgetLocalizedMessage(Locale locale)This method gets the resolved and localized message.voidgetLocalizedMessage(Locale locale, Appendable appendable)This method writes thelocalized messageto the givenAppendable.StringgetMessage()ATTENTION:
In most cases you wand to useLocalizable.getLocalizedMessage(Locale)instead of this method.LocalizablegetNlsMessage()static LocalizablegetNlsMessage(Throwable error)UUIDgetUuid()This method gets theUUIDof thisApplicationException.booleanisForUser()Note: Please consider usingnet.sf.mmm.nls.exception.NlsExceptionwith i18n support in case you are creating exceptions for end-users.booleanisTechnical()Determines if this is a technical exception.voidprintStackTrace(Locale locale, Appendable buffer)This method prints the stack trace with localized exception message(s).StringtoString()StringtoString(Locale locale)LiketoString()but using the specifiedLocale.AppendabletoString(Locale locale, Appendable appendable)appendsthe localized string representation of this exception.-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.mmm.base.i18n.Localizable
getArgument, getLocalizedMessage, toLocalizable
-
-
-
-
Constructor Detail
-
ApplicationException
public ApplicationException(String message)
The constructor.- Parameters:
message- themessagedescribing the problem briefly.
-
ApplicationException
public ApplicationException(Localizable message)
The constructor.- Parameters:
message- themessagedescribing the problem briefly.
-
ApplicationException
public ApplicationException(Localizable message, Throwable cause)
The constructor.
-
ApplicationException
protected ApplicationException(String message, Throwable cause, UUID uuid)
The constructor.
-
ApplicationException
protected ApplicationException(Localizable message, Throwable cause, UUID uuid)
The constructor.
-
-
Method Detail
-
getUuid
public final UUID getUuid()
This method gets theUUIDof thisApplicationException. When a newApplicationExceptionis created, aUUIDis assigned. In case theApplicationExceptionis created from anotherApplicationExceptionas cause, the existingUUIDwill be used from that cause. Otherwise a newUUIDis generated.
TheUUIDwill appear in thestacktracebut NOT in themessage. It will therefore be written to log-files if this exception is logged. If you supply theUUIDto the end-user, he can provide it with the problem report so an administrator or software developer can easily find the stacktrace in the log-files.- Returns:
- the
UUIDof this object.
-
getMessage
public String getMessage()
Description copied from interface:LocalizableATTENTION:
In most cases you wand to useLocalizable.getLocalizedMessage(Locale)instead of this method.- Specified by:
getMessagein interfaceLocalizable- Overrides:
getMessagein classThrowable- Returns:
- the untranslated message with arguments filled in. This results in the message in its original language that should typically be English.
- See Also:
Localizable.getLocalizedMessage()
-
getNlsMessage
public Localizable getNlsMessage()
- Returns:
- the
Localizablemessage describing the problem. - See Also:
getMessage(),getLocalizedMessage(Locale)
-
getLocalizedMessage
public String getLocalizedMessage(Locale locale)
Description copied from interface:LocalizableThis method gets the resolved and localized message.- Specified by:
getLocalizedMessagein interfaceLocalizable- Parameters:
locale- is the locale to translate to.- Returns:
- the localized message.
-
getLocalizedMessage
public void getLocalizedMessage(Locale locale, Appendable appendable)
Description copied from interface:Localizable- Specified by:
getLocalizedMessagein interfaceLocalizable- Parameters:
locale- theLocaleto translate to.appendable- theAppendablewhere towritethe message to.- See Also:
Localizable.getLocalizedMessage(Locale)
-
printStackTrace
public void printStackTrace(Locale locale, Appendable buffer)
This method prints the stack trace with localized exception message(s).- Parameters:
locale- is the locale to translate to.buffer- is where to write the stack trace to.- Throws:
IllegalStateException- if the givenbufferproduced anIOException.
-
isTechnical
public boolean isTechnical()
Determines if this is a technical exception.- A technical exception is an unexpected situation that is to be logged on error level and should be analyzed by
the operators or software developers of the system. Further in such case the end-user can typically do nothing
about the problem (except to retry his operation) and will typically not understand the problem. Therefore a
generic message should be
displayed to the end-userin such case. - A non technical exception is called user failure. It is an undesired but NOT abnormal situation (e.g.
a mandatory field was not filled). It should be logged on a level less than error (typically info). The
messageis typicallyintended for to end-usersand has to be easy to understand.
- Returns:
trueif this is a technical exception,falseif this is a user error.- See Also:
isForUser()
- A technical exception is an unexpected situation that is to be logged on error level and should be analyzed by
the operators or software developers of the system. Further in such case the end-user can typically do nothing
about the problem (except to retry his operation) and will typically not understand the problem. Therefore a
generic message should be
-
isForUser
public boolean isForUser()
Note: Please consider usingnet.sf.mmm.nls.exception.NlsExceptionwith i18n support in case you are creating exceptions for end-users.
-
getCode
public String getCode()
This method gets the code that identifies the detailed type of this object. WhileUUIDis unique per instance of aApplicationExceptionthis code is a short and readable identifier representing theApplicationExceptionClass. The default implementation returns thesimple name. However, the code should remain stable after refactoring (so at least after the rename the previous code should be returned asStringliteral). This code may be used as a compact identifier to reference the related problem or information as well as for automatic tests of error situations that should remain stable even if the message text gets improved or the locale is unknown.- Returns:
- the error code.
-
toString
public String toString(Locale locale)
LiketoString()but using the specifiedLocale.- Parameters:
locale- is theLocaleused forgetLocalizedMessage(Locale).- Returns:
- the localized string representation of this exception as described in
toString(Locale, Appendable)
-
toString
public Appendable toString(Locale locale, Appendable appendable)
appendsthe localized string representation of this exception. It is defined as following:«
classname»: [«custom-code»: ]«message»- Parameters:
locale- is theLocaleused forgetLocalizedMessage(Locale).appendable- is the buffer toappendto. Will be created asStringBuilderifnullis provided.- Returns:
- the provided
Appendableor the created one ifnullwas given.
-
getNlsMessage
public static Localizable getNlsMessage(Throwable error)
- Parameters:
error- theThrowable.- Returns:
- the
NLS message.
-
-