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
TResultThe 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>.ValueOneOfBase<TResult, Exception>.IndexOneOfBase<TResult, Exception>.IsT0OneOfBase<TResult, Exception>.IsT1OneOfBase<TResult, Exception>.AsT0OneOfBase<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
Methods
Failed(Exception)
Creates a failed Catch<TResult>.
public static Catch<TResult> Failed(Exception error)
Parameters
errorExceptionThe 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
valueTResultThe value.
Returns
- Catch<TResult>
The created Result<TError>.
TryGetException(out Exception?)
Try to get the error.
public bool TryGetException(out Exception? error)
Parameters
errorExceptionThe 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
resultTResultThe 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
objCatch<TResult>
Returns
explicit operator TResult(Catch<TResult>)
public static explicit operator TResult(Catch<TResult> obj)
Parameters
objCatch<TResult>
Returns
- TResult
implicit operator Catch<TResult>(Exception)
public static implicit operator Catch<TResult>(Exception error)
Parameters
errorException
Returns
- Catch<TResult>
implicit operator Catch<TResult>(TResult)
public static implicit operator Catch<TResult>(TResult value)
Parameters
valueTResult
Returns
- Catch<TResult>