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

Side by Side Diff: runtime/tests/vm/dart/isolate_unhandled_exception_test2.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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:io';
7
8 // Tests that an isolate's keeps message handling working after
9 // throwing an unhandled exception, if there is a top level callback
10 // method that returns whether to continue handling messages or not.
11 // This test verifies that a default-named callback function is called
12 // when no callback is specified in Isolate.spawnFunction.
13
14 // Note: this test will hang if an uncaught exception isn't handled,
15 // either by an error in the callback or it returning false.
16
17 void entry() {
18 port.receive((message, replyTo) {
19 if (message == 'throw exception') {
20 throw new RuntimeError('ignore this exception');
21 }
22 replyTo.call('hello');
23 port.close();
24 });
25 }
26
27 bool _unhandledExceptionCallback(IsolateUnhandledException e) {
28 return e.source.message == 'ignore this exception';
29 }
30
31 void main() {
32 var isolate_port = spawnFunction(entry);
33
34 // Send a message that will cause an ignorable exception to be thrown.
35 Future f = isolate_port.call('throw exception');
36 f.onComplete((future) {
37 // Exception wasn't ignored as it was supposed to be.
38 print('failed handling exception');
39 exit(1);
40 });
41
42 // Verify that isolate can still handle messages.
43 isolate_port.call('hi').onComplete((future) {
44 if (future.exception != null) {
45 print('unhandled exception: ${future.exception}');
46 exit(1);
47 }
48 if (future.value != 'hello') {
49 print('unexpected response: ${future.value}');
50 exit(1);
51 }
52 exit(0);
53 });
54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698