Package com.kosdev.kos.commons.util
Class ReasonException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.kosdev.kos.commons.util.ReasonException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SerialNumberException,UnknownNodeIdException
Exception that contains a reason code and optional reason data. Reason codes
are typically camel case strings that indicate an error in a human readable
format. For example:
"errNotConnected" or "userCancelled".
Reason codes are easy to read in logs and payload responses and don't require
a master list as numeric codes would require. KOS uses reason codes extensively.
ReasonException can combine a reason code along with associated data.
Unlike typical exceptions that contain data, ReasonException is designed
to be serializable to json. This includes the ability to throw a ReasonException
in an endpoint callback and have the exception captured and encoded in the response
automatically. When adding data to a ReasonException a view class is always
provided which is the JsonView that will be applied to the data when it
is serialized.
- Since:
- 1
- Version:
- 1
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionReasonException(String reason) Create an exception with a reason code.ReasonException(String reason, ReasonData reasonData) Create an exception with reason code and associated data.ReasonException(String reason, ReasonData reasonData, Throwable causedBy) Create an exception with reason code and associated data.ReasonException(String reason, Object data, Class<?> view) Create an exception with reason code and associated data.ReasonException(String reason, Object data, Class<?> view, Throwable causedBy) Create an exception with reason code and associated data.ReasonException(String reason, Throwable causedBy) Create an exception with a reason code and caused by exception. -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
ReasonException
Create an exception with a reason code.- Parameters:
reason- the reason code- Since:
- 1
-
ReasonException
Create an exception with reason code and associated data.- Parameters:
reason- the reason codedata- data associated with the exceptionview- theJsonViewused to serialize the data- Since:
- 1
-
ReasonException
Create an exception with reason code and associated data.- Parameters:
reason- the reason codereasonData- the data andJsonViewused to serialize the data- Since:
- 1
-
ReasonException
Create an exception with a reason code and caused by exception.- Parameters:
reason- the reason codecausedBy- exception that caused this exception- Since:
- 1
-
ReasonException
Create an exception with reason code and associated data.- Parameters:
reason- the reason codedata- data associated with the exceptionview- theJsonViewused to serialize the datacausedBy- exception that caused this exception- Since:
- 1
-
ReasonException
Create an exception with reason code and associated data.- Parameters:
reason- the reason codereasonData- the data andJsonViewused to serialize the datacausedBy- exception that caused this exception- Since:
- 1
-
-
Method Details
-
getReason
-
getReasonData
-