OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:isolate'; |
| 6 import 'dart:async'; |
| 7 |
| 8 import 'package:stack_trace/stack_trace.dart'; |
| 9 |
| 10 /// Capture any top-level errors (mostly lazy syntax errors, since other are |
| 11 /// caught below) and report them to the parent isolate. |
| 12 void catchIsolateErrors() { |
| 13 var errorPort = new ReceivePort(); |
| 14 // Aet errors non-fatal because otherwise they'll be double-printed. |
| 15 Isolate.current.setErrorsFatal(false); |
| 16 Isolate.current.addErrorListener(errorPort.sendPort); |
| 17 errorPort.listen((message) { |
| 18 // Masquerade as an IsoalteSpawnException because that's what this would |
| 19 // be if the error had been detected statically. |
| 20 var error = new IsolateSpawnException(message[0]); |
| 21 var stackTrace = |
| 22 message[1] == null ? new Trace([]) : new Trace.parse(message[1]); |
| 23 Zone.current.handleUncaughtError(error, stackTrace); |
| 24 }); |
| 25 } |
OLD | NEW |