runWithInvariant<R> method
Runs body and evaluates invariant afterward, even if body throws.
Returns the result of body when both the operation and invariant check
succeed. If body throws and the invariant check succeeds, the body's
exception propagates. If the invariant check also fails, the invariant
failure takes precedence.
Implementation
@nonVirtual
R runWithInvariant<R>(String description, R Function() body) {
try {
final result = body();
return result;
} finally {
_evaluateInvariant(description);
}
}