| 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 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 it was created with an |
| 10 // unhandled exception callback that returns true (continue handling). |
| 11 // This test verifies that a callback function specified in |
| 12 // Isolate.spawnFunction is called. |
| 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 exceptionCallback(IsolateUnhandledException e) { |
| 28 return e.source.message == 'ignore this exception'; |
| 29 } |
| 30 |
| 31 void main() { |
| 32 var isolate_port = spawnFunction(entry, exceptionCallback); |
| 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 } |
| OLD | NEW |