java.lang.Object
java.lang.Throwable
java.lang.Exception
com.github.sttk.sabi.errs.Err
- All Implemented Interfaces:
Serializable
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addAsyncHandler
(ErrHandler handler) Adds anErrHandler
object which is executed asynchronously just after anErr
is created.static void
addSyncHandler
(ErrHandler handler) Adds anErrHandler
object which is executed synchronously just after anErr
is created.static void
fixCfg()
Fixes configuration ofErr
.Gets a field value of the reason object by the specifiedEnum
name.Gets a field value of the reason object by the specified name.protected String
Gets the name of the source file of this error occurance.protected int
Gets the line number in the source file of this error occurence.Gets a message expresses the content of this exception.Gets the reason'sRecord
instance of this exception.Gets the simple name of this reason's class.Gets the package full name of this reason's class.Gets a map which contains variables that represent error situation.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
Err
A constructor which constructs a newErr
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
A constructor which constructs a newErr
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
Gets the reason'sRecord
instance of this exception.- Returns:
- The reason of this exception.
-
getReasonName
Gets the simple name of this reason's class.- Returns:
- The simple name of this reason's class.
-
getReasonPackage
Gets the package full name of this reason's class.- Returns:
- The package full name of this reason's class.
-
getMessage
Gets a message expresses the content of this exception.- Overrides:
getMessage
in classThrowable
- Returns:
- A error message.
-
get
Gets a field value of the reason object by the specified name. If the specified named field is not found in the reason of thisErr
, 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
-
getSituation
Gets a map which contains variables that represent error situation.- Returns:
- A map of error situation variables.
-
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
Adds anErrHandler
object which is executed synchronously just after anErr
is created. Handlers added with this method are executed in the order of addition and stop if one of the handlers throws aRuntimeException
or anError
.- Parameters:
handler
- AnErrHandler
object.
-
addAsyncHandler
Adds anErrHandler
object which is executed asynchronously just after anErr
is created. Handlers don't stop even if one of the handlers throw aRuntimeException
or anError
.- Parameters:
handler
- AnErrHandler
object.
-
fixCfg
public static void fixCfg()Fixes configuration ofErr
. After calling this method, any moreErrHandler
s cannot be registered, and notification ofErr
creations becomes effective.
-