reportError method Null safety
- FlutterErrorDetails details
Calls onError with the given details, unless it is null.
When calling this from a
catch
block consider annotating the method
containing the catch
block with
@pragma('vm:notify-debugger-on-exception')
to allow an attached debugger
to treat the exception as unhandled. This means instead of executing the
catch
block, the debugger can break at the original source location from
which the exception was thrown.
@pragma('vm:notify-debugger-on-exception')
void doSomething() {
try {
methodThatMayThrow();
} catch (exception, stack) {
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
stack: stack,
library: 'example library',
context: ErrorDescription('while doing something'),
));
}
}
Implementation
static void reportError(FlutterErrorDetails details) {
assert(details != null);
assert(details.exception != null);
onError?.call(details);
}