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.

Source

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;
}