Class Catch<TResult>

Namespace
Cratis.Monads
Assembly
Cratis.Fundamentals.dll

Represents the result of trying an execution that can return a result or potentially produce an Exception.

public class Catch<TResult> : OneOfBase<TResult, Exception>, IOneOf

Type Parameters

TResult

The result type.

Inheritance
OneOfBase<TResult, Exception>
Catch<TResult>
Implements
IOneOf
Inherited Members
OneOfBase<TResult, Exception>.TryPickT0(out TResult, out Exception)
OneOfBase<TResult, Exception>.TryPickT1(out Exception, out TResult)
OneOfBase<TResult, Exception>.ToString()
OneOfBase<TResult, Exception>.GetHashCode()
OneOfBase<TResult, Exception>.Value
OneOfBase<TResult, Exception>.Index
OneOfBase<TResult, Exception>.IsT0
OneOfBase<TResult, Exception>.IsT1
OneOfBase<TResult, Exception>.AsT0
OneOfBase<TResult, Exception>.AsT1
Extension Methods

Properties

IsSuccess

Gets a value indicating whether the execution was successful, meaning it has a result.

public bool IsSuccess { get; }

Property Value

bool

Methods

Failed(Exception)

Creates a failed Catch<TResult>.

public static Catch<TResult> Failed(Exception error)

Parameters

error Exception

The optional error.

Returns

Catch<TResult>

The created Result<TError>.

RethrowError()

Rethrows the Exception error if any, preserving the correct stack trace.

public void RethrowError()

Success(TResult)

Creates a successful Catch<TResult>.

public static Catch<TResult> Success(TResult value)

Parameters

value TResult

The value.

Returns

Catch<TResult>

The created Result<TError>.

TryGetException(out Exception?)

Try to get the error.

public bool TryGetException(out Exception? error)

Parameters

error Exception

The optional error.

Returns

bool

A boolean indicating whether the error was present.

TryGetResult(out TResult)

Try to get the result TResult.

public bool TryGetResult(out TResult result)

Parameters

result TResult

The result.

Returns

bool

A boolean indicating whether the result was present.

Operators

explicit operator Exception(Catch<TResult>)

public static explicit operator Exception(Catch<TResult> obj)

Parameters

obj Catch<TResult>

Returns

Exception

explicit operator TResult(Catch<TResult>)

public static explicit operator TResult(Catch<TResult> obj)

Parameters

obj Catch<TResult>

Returns

TResult

implicit operator Catch<TResult>(Exception)

public static implicit operator Catch<TResult>(Exception error)

Parameters

error Exception

Returns

Catch<TResult>

implicit operator Catch<TResult>(TResult)

public static implicit operator Catch<TResult>(TResult value)

Parameters

value TResult

Returns

Catch<TResult>