OLD | NEW |
| (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 library isolate_unhandled_exception_test2; | |
6 | |
7 import 'dart:isolate'; | |
8 | |
9 // Tests that an isolate's keeps message handling working after | |
10 // throwing an unhandled exception, if there is a top level callback | |
11 // method that returns whether to continue handling messages or not. | |
12 // This test verifies that a default-named callback function is called | |
13 // when no callback is specified in Isolate.spawnFunction. | |
14 | |
15 // Note: this test will hang if an uncaught exception isn't handled, | |
16 // either by an error in the callback or it returning false. | |
17 | |
18 void entry() { | |
19 port.receive((message, replyTo) { | |
20 if (message == 'throw exception') { | |
21 replyTo.call('throwing exception'); | |
22 throw new UnsupportedError('ignore this exception'); | |
23 } | |
24 replyTo.call('hello'); | |
25 port.close(); | |
26 }); | |
27 } | |
28 | |
29 bool _unhandledExceptionCallback(IsolateUnhandledException e) { | |
30 return e.source.message == 'ignore this exception'; | |
31 } | |
32 | |
33 void main() { | |
34 var isolate_port = spawnFunction(entry); | |
35 | |
36 // Send a message that will cause an ignorable exception to be thrown. | |
37 Future f = isolate_port.call('throw exception'); | |
38 f.onComplete((future) { | |
39 // Exception wasn't ignored as it was supposed to be. | |
40 Expect.equals(null, future.exception); | |
41 }); | |
42 | |
43 // Verify that isolate can still handle messages. | |
44 isolate_port.call('hi').onComplete((future) { | |
45 Expect.equals(null, future.exception); | |
46 Expect.equals('hello', future.value); | |
47 }); | |
48 | |
49 } | |
OLD | NEW |