verifyThrows function

bool verifyThrows(
  1. void fn(), [
  2. String? message
])

Verify that a condition throws an exception.

Example:

verifyThrows(() => divide(1, 0), 'Division by zero should throw');

Returns true if an exception was thrown, false otherwise.

Implementation

bool verifyThrows(void Function() fn, [String? message]) {
  try {
    fn();
    final msg = message ?? 'Expected exception to be thrown';
    _verificationFailures.add(msg);
    return false;
  } catch (_) {
    return true;
  }
}