Class Err

All Implemented Interfaces:
Serializable

public final class Err extends Exception
Err is the exception class with a reason.
This class has a record value which indicates a reason by which this exception is caused. A record as a reason can have some fields that helps to know error situation where this exception is caused.
The example code of creating and throwing an excepton is as follows:

   public record FailToDoSomething(String name, int value) {}

   throw new Err(new FailToDoSomething("abc", 123));
 
See Also:
  • Constructor Details

    • Err

      public Err(Record reason)
      A constructor which constructs a new Err instance with a specified reason. A reason is a structore type of which name expresses what is a reason.
      Parameters:
      reason - A reason of this exception.
    • Err

      public Err(Record reason, Throwable cause)
      A constructor which constructs a new Err instance with a specified reason and an cause. A reason is a structore type of which name expresses what is a reason.
      Parameters:
      reason - A reason of this exception.
      cause - A cause exception.
  • Method Details

    • getReason

      public Record getReason()
      Gets the reason's Record instance of this exception.
      Returns:
      The reason of this exception.
    • getReasonName

      public String getReasonName()
      Gets the simple name of this reason's class.
      Returns:
      The simple name of this reason's class.
    • getReasonPackage

      public String getReasonPackage()
      Gets the package full name of this reason's class.
      Returns:
      The package full name of this reason's class.
    • getMessage

      public String getMessage()
      Gets a message expresses the content of this exception.
      Overrides:
      getMessage in class Throwable
      Returns:
      A error message.
    • get

      public Object get(String name)
      Gets a field value of the reason object by the specified name. If the specified named field is not found in the reason of this Err, this method finds a same named field in reasons of cause exception hierarchically.
      Parameters:
      name - A field name of the reason object in this exception.
      Returns:
      A field value of the reason object by the specified name.
    • get

      public Object get(Enum<?> name)
      Gets a field value of the reason object by the specified Enum name. If the specified named field is not found in the reason of this Err, this method finds a same named field in reasons of cause exception hierarchically.
      Parameters:
      name - An Enum that same with a field name of the reason object in this exception.
      Returns:
      A field value of the reason object by the specified Enum name.
    • getSituation

      public Map<String,Object> getSituation()
      Gets a map which contains variables that represent error situation.
      Returns:
      A map of error situation variables.
    • getFileName

      protected String getFileName()
      Gets the name of the source file of this error occurance. This method can return null if this information is unavailable.
      Returns:
      The name of the source file of this error occurence.
    • getLineNumber

      protected int getLineNumber()
      Gets the line number in the source file of this error occurence. This method can return a negative number if this information is unavailable.
      Returns:
      The line number in the source file of this error occurence.
    • addSyncHandler

      public static void addSyncHandler(ErrHandler handler)
      Adds an ErrHandler object which is executed synchronously just after an Err is created. Handlers added with this method are executed in the order of addition and stop if one of the handlers throws a RuntimeException or an Error.
      Parameters:
      handler - An ErrHandler object.
    • addAsyncHandler

      public static void addAsyncHandler(ErrHandler handler)
      Adds an ErrHandler object which is executed asynchronously just after an Err is created. Handlers don't stop even if one of the handlers throw a RuntimeException or an Error.
      Parameters:
      handler - An ErrHandler object.
    • fixCfg

      public static void fixCfg()
      Fixes configuration of Err. After calling this method, any more ErrHandlers cannot be registered, and notification of Err creations becomes effective.