Class ReasonException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SerialNumberException, UnknownNodeIdException

public class ReasonException extends RuntimeException
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 Details

    • ReasonException

      public ReasonException(String reason)
      Create an exception with a reason code.
      Parameters:
      reason - the reason code
      Since:
      1
    • ReasonException

      public ReasonException(String reason, Object data, Class<?> view)
      Create an exception with reason code and associated data.
      Parameters:
      reason - the reason code
      data - data associated with the exception
      view - the JsonView used to serialize the data
      Since:
      1
    • ReasonException

      public ReasonException(String reason, ReasonData reasonData)
      Create an exception with reason code and associated data.
      Parameters:
      reason - the reason code
      reasonData - the data and JsonView used to serialize the data
      Since:
      1
    • ReasonException

      public ReasonException(String reason, Throwable causedBy)
      Create an exception with a reason code and caused by exception.
      Parameters:
      reason - the reason code
      causedBy - exception that caused this exception
      Since:
      1
    • ReasonException

      public ReasonException(String reason, Object data, Class<?> view, Throwable causedBy)
      Create an exception with reason code and associated data.
      Parameters:
      reason - the reason code
      data - data associated with the exception
      view - the JsonView used to serialize the data
      causedBy - exception that caused this exception
      Since:
      1
    • ReasonException

      public ReasonException(String reason, ReasonData reasonData, Throwable causedBy)
      Create an exception with reason code and associated data.
      Parameters:
      reason - the reason code
      reasonData - the data and JsonView used to serialize the data
      causedBy - exception that caused this exception
      Since:
      1
  • Method Details

    • getReason

      public String getReason()
    • getReasonData

      public ReasonData getReasonData()