ResTThrowIfErrE(FuncString, E) Method
Returns the result back when
IsOk; throws an exception of
E when
IsErr.
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.
Namespace: Orx.Fun.ResultAssembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
public Res<T> ThrowIfErr<E>(
Func<string, E> errorMessageToException
)
where E : Exception
- errorMessageToException FuncString, E
- Function that crates the desired exception from the error message, to be used if the result IsErr.
- E
- Type of the exception to be thrown.
ResT