Struct Outcome<T>

Namespace
Kevlar
Assembly
Kevlar.dll

The result of an execution: either a value or a captured exception, never both. Kevlar strategies pass outcomes between pipeline layers instead of throwing, so exceptions only pay their cost once, at the pipeline boundary.

public readonly struct Outcome<T>

Type Parameters

T

The result type of the execution.

Inherited Members

Properties

Exception

The captured exception, or null if the execution produced a result.

public Exception? Exception { get; }

Property Value

Exception

IsSuccess

true when the execution produced a result rather than an exception.

public bool IsSuccess { get; }

Property Value

bool

Result

The result value. Only meaningful when Exception is null. For flow-analysis-friendly access, use TryGetResult(out T).

public T? Result { get; }

Property Value

T

Methods

FromException(Exception)

Creates an outcome holding a captured exception.

public static Outcome<T> FromException(Exception exception)

Parameters

exception Exception

Returns

Outcome<T>

FromResult(T)

Creates an outcome holding a result value.

public static Outcome<T> FromResult(T result)

Parameters

result T

Returns

Outcome<T>

GetResultOrRethrow()

Returns the result, or rethrows the captured exception with its original stack trace preserved.

public T GetResultOrRethrow()

Returns

T

ToString()

public override string ToString()

Returns

string

TryGetResult(out T)

Tries to get the result without throwing the captured exception.

public bool TryGetResult(out T result)

Parameters

result T

The result value when the outcome is successful; otherwise, the default value of T.

Returns

bool

true when the execution produced a result; otherwise, false.

Operators

implicit operator Outcome(Outcome<T>)

Converts a result-bearing outcome to its void success-or-failure representation.

public static implicit operator Outcome(Outcome<T> outcome)

Parameters

outcome Outcome<T>

Returns

Outcome