API Reference ResultException - ulfbou/Zentient.Results GitHub Wiki

❗ API Reference: classZentient.Results.ResultException

namespace Zentient.Results

📖 Summary

Represents 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.


📌 Metadata

Property Value
📦 Assembly Zentient.Results.dll
👁️ Visibility public
🧬 Inherits System.Exception
⚙️ Type Kind class
🏷️ Attributes [Serializable]

🏗 Constructors

🔹 ResultException(IReadOnlyList<ErrorInfo> errors)

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 ArgumentNullException if errors is null.


🔹 ResultException(string message, IReadOnlyList<ErrorInfo> errors)

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 ArgumentNullException if errors is null.


🔹 ResultException(string message, Exception innerException, IReadOnlyList<ErrorInfo> errors)

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 ArgumentNullException if errors is null.


📂 Properties

📄 Errors

public IReadOnlyList<ErrorInfo> Errors { get; }

Gets the immutable collection of structured ErrorInfo associated with this failure.

Type Description
IReadOnlyList<ErrorInfo> Immutable error information list.

🧠 Remarks

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.

✅ Example Usage

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);
⚠️ **GitHub.com Fallback** ⚠️