expectErr method

E expectErr(
  1. String message
)

Unwraps the error value, or throws an exception with message.

Use this when you're certain the result should be Err, but want to provide a custom error message if it's not. The original stack trace is preserved. Primarily useful for testing or assertions. For normal error handling, prefer err, isErr, or pattern matching.

Example:

final error = result.expectErr('Operation should have failed');

Implementation

E expectErr(String message) => switch (this) {
  Ok() => throw Exception(message),
  Err(:final error) => error,
};