W3cubDocs

/Dart 2

errors property

Stream errors

Returns a broadcast stream of uncaught errors from the isolate.

Each error is provided as an error event on the stream.

The actual error object and stackTraces will not necessarily be the same object types as in the actual isolate, but they will always have the same Object.toString result.

This stream is based on addErrorListener and removeErrorListener.

Implementation

Stream get errors {
  StreamController controller;
  RawReceivePort port;
  void handleError(message) {
    String errorDescription = message[0];
    String stackDescription = message[1];
    var error = new RemoteError(errorDescription, stackDescription);
    controller.addError(error, error.stackTrace);
  }

  controller = new StreamController.broadcast(
      sync: true,
      onListen: () {
        port = new RawReceivePort(handleError);
        this.addErrorListener(port.sendPort);
      },
      onCancel: () {
        this.removeErrorListener(port.sendPort);
        port.close();
        port = null;
      });
  return controller.stream;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-isolate/Isolate/errors.html