Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Unified Diff: runtime/tests/vm/dart/isolate_unhandled_exception_test.dart

Issue 11558034: Second version of support for specifying an unhandled exception callback (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/tests/vm/dart/isolate_unhandled_exception_test.dart
===================================================================
--- runtime/tests/vm/dart/isolate_unhandled_exception_test.dart (revision 0)
+++ runtime/tests/vm/dart/isolate_unhandled_exception_test.dart (revision 0)
@@ -0,0 +1,50 @@
+import 'dart:isolate';
+import 'dart:io';
+
+// Tests that an isolate's keeps message handling working after
+// throwing an unhandled exception, if it was created with an
+// unhandled exception callback that returns true (continue handling).
+// This test verifies that a callback function specified in
+// Isolate.spawnFunction is called.
+
+// Note: this test will hang if an uncaught exception isn't handled,
+// either by an error in the callback or it returning false.
+
+void entry() {
+ port.receive((message, replyTo) {
+ if (message == 'throw exception') {
+ throw new RuntimeError('ignore this exception');
+ }
+ replyTo.call('hello');
+ port.close();
+ });
+}
+
+bool exceptionCallback(IsolateUnhandledException e) {
+ return e.source.message == 'ignore this exception';
+}
+
+void main() {
+ var isolate_port = spawnFunction(entry, exceptionCallback);
+
+ // Send a message that will cause an ignorable exception to be thrown.
+ Future f = isolate_port.call('throw exception');
+ f.onComplete((future) {
+ // Exception wasn't ignored as it was supposed to be.
+ print('failed handling exception');
+ exit(1);
+ });
+
+ // Verify that isolate can still handle messages.
+ isolate_port.call('hi').onComplete((future) {
+ if (future.exception != null) {
+ print('unhandled exception: ${future.exception}');
+ exit(1);
+ }
+ if (future.value != 'hello') {
+ print('unexpected response: ${future.value}');
+ exit(1);
+ }
+ exit(0);
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698