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
TResultThe result type.
TErrorThe 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>.ValueOneOfBase<TResult, TError, Exception>.IndexOneOfBase<TResult, TError, Exception>.IsT0OneOfBase<TResult, TError, Exception>.IsT1OneOfBase<TResult, TError, Exception>.IsT2OneOfBase<TResult, TError, Exception>.AsT0OneOfBase<TResult, TError, Exception>.AsT1OneOfBase<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
Methods
Failed(Exception)
Creates a failed Catch<TResult, TError>.
public static Catch<TResult, TError> Failed(Exception error)
Parameters
errorExceptionThe 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
errorTErrorThe 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
valueTResultThe 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
errorTErrorThe 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
errorExceptionThe 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
resultTResultThe 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
objCatch<TResult, TError>
Returns
explicit operator TResult(Catch<TResult, TError>)
public static explicit operator TResult(Catch<TResult, TError> obj)
Parameters
objCatch<TResult, TError>
Returns
- TResult
explicit operator TError(Catch<TResult, TError>)
public static explicit operator TError(Catch<TResult, TError> obj)
Parameters
objCatch<TResult, TError>
Returns
- TError
implicit operator Catch<TResult, TError>(Exception)
public static implicit operator Catch<TResult, TError>(Exception error)
Parameters
errorException
Returns
- Catch<TResult, TError>
implicit operator Catch<TResult, TError>(TResult)
public static implicit operator Catch<TResult, TError>(TResult value)
Parameters
valueTResult
Returns
- Catch<TResult, TError>
implicit operator Catch<TResult, TError>(TError)
public static implicit operator Catch<TResult, TError>(TError errorType)
Parameters
errorTypeTError
Returns
- Catch<TResult, TError>