unwrapErr method

  1. @override
E unwrapErr()
override

Returns the contained Err (failure) value.

Throws an exception

Throws an exception if the value is an Ok, with an exception message provided by the Ok's value.

Examples

Result<int, String> x = Ok(2);
x.unwrapErr(); // Throws an exception with message `called `Result.unwrapErr()` on an `Ok` value: 2`

Result<int, String> y = Err('emergency failure');
expect(y.unwrapErr(), "emergency failure");

Implementation

@override
E unwrapErr() {
  throw UnwrapErrException(
    okString: v.toString(),
  );
}