Class ExceptionError

Namespace
REslava.Result
Assembly
REslava.Result.dll

Wraps a .NET Exception as a typed error reason. Automatically captures the exception type, stack trace, and inner exception message as tags. Produced automatically by Try(Action, Func<Exception, IError>?) and TryAsync(Func<Task>, Func<Exception, IError>?, CancellationToken).

public class ExceptionError : Reason<ExceptionError>, IReasonMetadata, IError, IReason
Inheritance
ExceptionError
Implements
Inherited Members
Extension Methods

Examples

var result = Result<string>.Try(() => File.ReadAllText("config.json"));
if (result.IsFailure)
{
    var ex = result.Errors.OfType<ExceptionError>().First();
    Console.WriteLine(ex.Exception.Message);      // original exception message
    Console.WriteLine(ex.Tags["ExceptionType"]);  // e.g. "FileNotFoundException"
}

Constructors

ExceptionError(Exception, string?, string?, int)

Creates an error from an exception, using the exception's own message.

public ExceptionError(Exception exception, string? callerMember = null, string? callerFile = null, int callerLine = 0)

Parameters

exception Exception
callerMember string
callerFile string
callerLine int

ExceptionError(string, Exception, string?, string?, int)

Creates an error with a custom message, preserving the original exception for diagnostics.

public ExceptionError(string message, Exception exception, string? callerMember = null, string? callerFile = null, int callerLine = 0)

Parameters

message string
exception Exception
callerMember string
callerFile string
callerLine int

Properties

Exception

Gets the original .NET exception that caused this error.

public Exception Exception { get; init; }

Property Value

Exception

Methods

CreateNew(string, ImmutableDictionary<string, object>)

Factory method for creating new instances (maintains immutability). Must be implemented by derived classes.

protected override ExceptionError CreateNew(string message, ImmutableDictionary<string, object> tags)

Parameters

message string
tags ImmutableDictionary<string, object>

Returns

ExceptionError