Returns the result back when IsOk; throws NullReferenceException 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();
// result will be:
// - Ok() if MakeApiCall succeeds and returns Ok;
// - the application will throw a NullReferenceException otherwise.
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.