Class Catch<TResult, TError>

Namespace
Cratis.Monads
Assembly
Cratis.Fundamentals.dll

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

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

Type Parameters

TResult

The result type.

TError

The error type.

Inheritance
OneOfBase<TResult, TError, Exception>
Catch<TResult, TError>
Implements
IOneOf
Inherited Members
OneOfBase<TResult, TError, Exception>.TryPickT0(out TResult, out OneOf<TError, Exception>)
OneOfBase<TResult, TError, Exception>.TryPickT1(out TError, out OneOf<TResult, Exception>)
OneOfBase<TResult, TError, Exception>.TryPickT2(out Exception, out OneOf<TResult, TError>)
OneOfBase<TResult, TError, Exception>.ToString()
OneOfBase<TResult, TError, Exception>.GetHashCode()
OneOfBase<TResult, TError, Exception>.Value
OneOfBase<TResult, TError, Exception>.Index
OneOfBase<TResult, TError, Exception>.IsT0
OneOfBase<TResult, TError, Exception>.IsT1
OneOfBase<TResult, TError, Exception>.IsT2
OneOfBase<TResult, TError, Exception>.AsT0
OneOfBase<TResult, TError, Exception>.AsT1
OneOfBase<TResult, TError, Exception>.AsT2
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, TError>.

public static Catch<TResult, TError> Failed(Exception error)

Parameters

error Exception

The error.

Returns

Catch<TResult, TError>

The created Result<TResult, TError>.

Failed(TError)

Creates a failed Catch<TResult, TError>.

public static Catch<TResult, TError> Failed(TError error)

Parameters

error TError

The error type.

Returns

Catch<TResult, TError>

The created Result<TResult, TError>.

RethrowError()

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

public void RethrowError()

Success(TResult)

Creates a successful Catch<TResult, TError>.

public static Catch<TResult, TError> Success(TResult value)

Parameters

value TResult

The value.

Returns

Catch<TResult, TError>

The created Result<TResult, TError>.

TryGetError(out TError?)

Try to get the error.

public bool TryGetError(out TError? error)

Parameters

error TError

The optional error.

Returns

bool

A boolean indicating whether the error was present.

TryGetException(out Exception?)

Try to get the exception.

public bool TryGetException(out Exception? error)

Parameters

error Exception

The optional exception.

Returns

bool

A boolean indicating whether the exception 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, TError>)

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

Parameters

obj Catch<TResult, TError>

Returns

Exception

explicit operator TResult(Catch<TResult, TError>)

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

Parameters

obj Catch<TResult, TError>

Returns

TResult

explicit operator TError(Catch<TResult, TError>)

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

Parameters

obj Catch<TResult, TError>

Returns

TError

implicit operator Catch<TResult, TError>(Exception)

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

Parameters

error Exception

Returns

Catch<TResult, TError>

implicit operator Catch<TResult, TError>(TResult)

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

Parameters

value TResult

Returns

Catch<TResult, TError>

implicit operator Catch<TResult, TError>(TError)

public static implicit operator Catch<TResult, TError>(TError errorType)

Parameters

errorType TError

Returns

Catch<TResult, TError>