Index: pkg/testing/lib/src/error_handling.dart |
diff --git a/pkg/testing/lib/src/error_handling.dart b/pkg/testing/lib/src/error_handling.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..325afed58adc909fe92d36df6e8c4c4241245221 |
--- /dev/null |
+++ b/pkg/testing/lib/src/error_handling.dart |
@@ -0,0 +1,30 @@ |
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE.md file. |
+ |
+library testing.error_handling; |
+ |
+import 'dart:async' show |
+ Future; |
+ |
+import 'dart:io' show |
+ exitCode, |
+ stderr; |
+ |
+import 'dart:isolate' show |
+ ReceivePort; |
+ |
+Future withErrorHandling(Future f()) async { |
+ final ReceivePort port = new ReceivePort(); |
+ try { |
+ return await f(); |
+ } catch (e, trace) { |
+ exitCode = 1; |
+ stderr.writeln(e); |
+ if (trace != null) { |
+ stderr.writeln(trace); |
+ } |
+ } finally { |
+ port.close(); |
+ } |
+} |