Class Err
Is the exception class with a reason.
This class has a property which indicates a reason for this exception. Typically the type of
this property is a record class. In this case, the class name of this record represents
the reason, and the fields of the record hold the situation where the exception occurred.
Optionally, this exception class can notify its instance creation to pre-registered exception
handlers. This notification feature can be enabled by specifying the command line argument
{@code --github.sttk.errs.notify=true} when an application using this library is started.
public record FailToDoSomething(String name, int value);
try
{
throw new Err(new FailToDoSomething("abc", 123));
}
catch (Err e)
{
Console.WriteLine(e.Message);
}
Implements
Inherited Members
Namespace: Errs
Assembly: Errs.dll
Syntax
public sealed class Err : Exception, ISerializable
Constructors
| Edit this page View SourceErr(object, Exception?, string, int)
Is the constructor which takes an object indicating the reason for this exception. In addition, this constructor takes the inner exception indicating the cause for this exception if any.
Declaration
public Err(object reason, Exception? innerException = null, string file = "", int line = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| object | reason | An object representing the reason for the exception. The type of this object identifies the kind of error and may contain additional error details. |
| Exception | innerException | The underlying exception that caused the error, if any. |
| string | file | The source file in which the error was created. This parameter is automatically populated by the compiler. |
| int | line | The line number at which the error was created. This parameter is automatically populated by the compiler. |
Properties
| Edit this page View SourceFile
The name of the source file of this exception occurrence.
Declaration
public string File { get; }
Property Value
| Type | Description |
|---|---|
| string | The name of the source file of this exception occurrence. |
Line
The line number of this exception occurrence in the source file.
Declaration
public int Line { get; }
Property Value
| Type | Description |
|---|---|
| int | The line number of this exception occurrence in the source file. |
Message
Gets a message that describes the current exception.
Declaration
public override string Message { get; }
Property Value
| Type | Description |
|---|---|
| string | The error message that explains the reason for the exception, or an empty string (""). |
Overrides
| Edit this page View SourceReason
The reason for this exception.
Declaration
public object Reason { get; }
Property Value
| Type | Description |
|---|---|
| object | The reason for this exception. |
Methods
| Edit this page View SourceAddAsyncHandler(AsyncErrHandler)
Adds an AsyncErrHandler object which is executed asynchronously just after
an Err is created. Handlers don't stop even if one of the handlers throw an
exception.
NOTE: This feature is enabled via the command line argument:
--github.sttk.errs.notify=true
Declaration
public static void AddAsyncHandler(AsyncErrHandler handler)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncErrHandler | handler | An AsyncErrHandler object. |
AddSyncHandler(SyncErrHandler)
Adds an SyncErrHandler 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 an exception.
NOTE: This feature is enabled via the command line argument:
--github.sttk.errs.notify=true
Declaration
public static void AddSyncHandler(SyncErrHandler handler)
Parameters
| Type | Name | Description |
|---|---|---|
| SyncErrHandler | handler | An SyncErrHandler object. |
FixHandlers()
Prevents further addition of error handler object to synchronous and asynchronous exception
handler lists. Before this is called, no Err is notified to the handlers.
After this is called, no new handlers can be added, and Err is notified to
the handlers.
NOTE: This feature is enabled via the command line argument:
--github.sttk.errs.notify=true
Declaration
public static void FixHandlers()
ToString()
Creates and returns a string representation of the current exception.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string representation of the current exception. |