Returns the result back when IsOk; throws a NullReferenceException when IsErr.
C#
static Res<User> QueryUser(..) {
// might fail; hence, returns a Res<User> rather than just User.
}
var result = QueryUser(..).ThrowIfErr();
// result will be:
// - Ok(user) if QueryUser succeeds and returns Ok of the user;
// - the application will throw 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.