onError property Null safety

ErrorCallback? onError

A callback that is invoked when an unhandled error occurs in the root isolate.

This callback must return true if it has handled the error. Otherwise, it must return false and a fallback mechanism such as printing to stderr will be used, as configured by the specific platform embedding via Settings::unhandled_exception_callback.

The VM or the process may exit or become unresponsive after calling this callback. The callback will not be called for exceptions that cause the VM or process to terminate or become unresponsive before the callback can be invoked.

This callback is not directly invoked by errors in child isolates of the root isolate. Programs that create new isolates must listen for errors on those isolates and forward the errors to the root isolate. An example of this can be found in the Flutter framework's compute function.

Implementation

ErrorCallback? get onError => _onError;
void onError=(ErrorCallback? callback)

Implementation

set onError(ErrorCallback? callback) {
  _onError = callback;
  _onErrorZone = Zone.current;
}