maybeThrowException function

void maybeThrowException(
  1. Object o,
  2. Invocation i
)

To be used within Fakes. The method calls this to throw an exception if a matching invocation has been registered. If not, the method can behave normally.

Implementation

void maybeThrowException(Object o, Invocation i) {
  // check the registry. Throw an error, or nothing.
  if (!expectations.containsKey(o)) {
    return;
  }
  for (final expectation in (expectations[o] ?? {}).entries) {
    if (_matches(expectation.key, i)) {
      throw expectation.value;
    }
  }
}