API Reference ResultException - ulfbou/Zentient.Results GitHub Wiki
namespace Zentient.ResultsRepresents a domain-specific exception thrown when an IResult indicates failure. Encapsulates one or more ErrorInfo instances and provides constructors for contextual messages and inner exceptions.
| Property | Value |
|---|---|
| 📦 Assembly | Zentient.Results.dll |
| 👁️ Visibility | public |
| 🧬 Inherits | System.Exception |
| ⚙️ Type Kind | class |
| 🏷️ Attributes | [Serializable] |
public ResultException(IReadOnlyList<ErrorInfo> errors)Creates a ResultException with a default message composed from error details.
| Parameter | Type | Description |
|---|---|---|
errors |
IReadOnlyList<ErrorInfo> |
Required list of error objects. |
Throws
ArgumentNullExceptioniferrorsisnull.
public ResultException(string message, IReadOnlyList<ErrorInfo> errors)Creates a ResultException with a custom message and error collection.
| Parameter | Type | Description |
|---|---|---|
message |
string |
Custom error message. |
errors |
IReadOnlyList<ErrorInfo> |
Required list of error objects. |
Throws
ArgumentNullExceptioniferrorsisnull.
public ResultException(string message, Exception innerException, IReadOnlyList<ErrorInfo> errors)Creates a ResultException with full control over message, inner exception, and errors.
| Parameter | Type | Description |
|---|---|---|
message |
string |
Custom error message. |
innerException |
Exception |
Inner exception cause. |
errors |
IReadOnlyList<ErrorInfo> |
Required list of error objects. |
Throws
ArgumentNullExceptioniferrorsisnull.
public IReadOnlyList<ErrorInfo> Errors { get; }Gets the immutable collection of structured ErrorInfo associated with this failure.
| Type | Description |
|---|---|
IReadOnlyList<ErrorInfo> |
Immutable error information list. |
This exception is the standard way to escalate a failed IResult into a .NET exception for scenarios where exceptions remain the primary error signaling mechanism (e.g., middleware, legacy integration, testing).
It enables:
- Bridging functional result-based errors with exception flows.
- Embedding rich domain error metadata in exceptions.
- Preserving structured failure context beyond textual messages.
IResult result = SomeOperation();
if (result.IsFailure)
throw new ResultException(result.Errors);IResult<MyData> result = FetchData();
if (result.IsFailure)
throw new ResultException("Data retrieval failed", result.Errors);