Show / Hide Table of Contents

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.

The example code of creating and throwing an exception is as follows:

public record FailToDoSomething(String name, int value);

try
{
    throw new Err(new FailToDoSomething("abc", 123));
}
catch (Err e)
{
    Console.WriteLine(e.Message);
}
Inheritance
object
Exception
Err
Implements
ISerializable
Inherited Members
Exception.GetBaseException()
Exception.GetType()
Exception.Data
Exception.HelpLink
Exception.HResult
Exception.InnerException
Exception.Source
Exception.StackTrace
Exception.TargetSite
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.ReferenceEquals(object, object)
Namespace: Errs
Assembly: Errs.dll
Syntax
public sealed class Err : Exception, ISerializable

Constructors

| Edit this page View Source

Err(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 Source

File

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.

| Edit this page View Source

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.

| Edit this page View Source

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
Exception.Message
| Edit this page View Source

Reason

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 Source

AddAsyncHandler(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.

| Edit this page View Source

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.

| Edit this page View Source

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()
| Edit this page View Source

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.

Overrides
Exception.ToString()

Implements

ISerializable
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX