Class Catch

Namespace
Cratis.Monads
Assembly
Cratis.Fundamentals.dll

Represents the result of trying an execution that potentially produce an Exception.

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

Properties

IsSuccess

Gets a value indicating whether the execution was successful.

public bool IsSuccess { get; }

Property Value

bool

Methods

Failed(Exception)

Creates a failed Catch.

public static Catch Failed(Exception error)

Parameters

error Exception

The error.

Returns

Catch

The created Catch.

Failed<TResult>(Exception)

Creates a failed Catch<TResult>.

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

Parameters

error Exception

The optional error.

Returns

Catch<TResult>

The created Result<TError>.

Type Parameters

TResult

The type of the result.

Failed<TResult, TError>(Exception)

Creates a failed Catch<TResult, TError>.

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

Parameters

error Exception

The error.

Returns

Catch<TResult, TError>

The created Result<TResult, TError>.

Type Parameters

TResult

The result type.

TError

The error type.

Failed<TResult, TError>(TError)

Creates a failed Catch<TResult, TError>.

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

Parameters

error TError

The error.

Returns

Catch<TResult, TError>

The created Result<TResult, TError>.

Type Parameters

TResult

The result type.

TError

The error type.

RethrowError()

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

public void RethrowError()

Success()

Creates a successful Catch.

public static Catch Success()

Returns

Catch

The created Catch.

Success<TResult>(TResult)

Creates a successful Catch<TResult>.

public static Catch<TResult> Success<TResult>(TResult result)

Parameters

result TResult

The result.

Returns

Catch<TResult>

The created Catch.

Type Parameters

TResult

The type of the result.

Success<TResult, TError>(TResult)

Creates a successful Catch<TResult, TError>.

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

Parameters

value TResult

The value.

Returns

Catch<TResult, TError>

The created Result<TResult, TError>.

Type Parameters

TResult

The result type.

TError

The error type.

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.

Operators

explicit operator Exception(Catch)

public static explicit operator Exception(Catch obj)

Parameters

obj Catch

Returns

Exception

implicit operator Catch(Exception)

public static implicit operator Catch(Exception error)

Parameters

error Exception

Returns

Catch