| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library testing.error_handling; | 5 library testing.error_handling; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show Future; |
| 8 Future; | |
| 9 | 8 |
| 10 import 'dart:io' show | 9 import 'dart:io' show exitCode, stderr; |
| 11 exitCode, | |
| 12 stderr; | |
| 13 | 10 |
| 14 import 'dart:isolate' show | 11 import 'dart:isolate' show ReceivePort; |
| 15 ReceivePort; | |
| 16 | 12 |
| 17 Future withErrorHandling(Future f()) async { | 13 Future withErrorHandling(Future f()) async { |
| 18 final ReceivePort port = new ReceivePort(); | 14 final ReceivePort port = new ReceivePort(); |
| 19 try { | 15 try { |
| 20 return await f(); | 16 return await f(); |
| 21 } catch (e, trace) { | 17 } catch (e, trace) { |
| 22 exitCode = 1; | 18 exitCode = 1; |
| 23 stderr.writeln(e); | 19 stderr.writeln(e); |
| 24 if (trace != null) { | 20 if (trace != null) { |
| 25 stderr.writeln(trace); | 21 stderr.writeln(trace); |
| 26 } | 22 } |
| 27 } finally { | 23 } finally { |
| 28 port.close(); | 24 port.close(); |
| 29 } | 25 } |
| 30 } | 26 } |
| OLD | NEW |