ResTThrowIfErrE(FuncString, E) Method

Returns the result back when IsOk; throws an exception of E when IsErr.
C#
static Res MakeApiCall() {
    // method that makes an api call.
    // might fail; hence, returns a Res rather than void.
}
var result = MakeApiCall().ThrowIfErr<HttpRequestException>(err => new(err));
// result will be:
// - Ok() if MakeApiCall succeeds and returns Ok;
// - the application will throw HttpRequestException created by the provided delegate otherwise.

Definition

Namespace: Orx.Fun.Result
Assembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
C#
public Res<T> ThrowIfErr<E>(
	Func<string, E> errorMessageToException
)
where E : Exception

Parameters

errorMessageToException  FuncString, E
Function that crates the desired exception from the error message, to be used if the result IsErr.

Type Parameters

E
Type of the exception to be thrown.

Return Value

ResT

See Also