| OLD | NEW |
| (Empty) | |
| 1 import 'dart:isolate'; |
| 2 import 'dart:io'; |
| 3 |
| 4 // Tests that an isolate's keeps message handling working after |
| 5 // throwing an unhandled exception, if it was created with an |
| 6 // unhandled exception callback that returns true (continue handling). |
| 7 // This test verifies that a callback function specified in |
| 8 // Isolate.spawnFunction is called. |
| 9 |
| 10 // Note: this test will hang if an uncaught exception isn't handled, |
| 11 // either by an error in the callback or it returning false. |
| 12 |
| 13 void entry() { |
| 14 port.receive((message, replyTo) { |
| 15 if (message == 'throw exception') { |
| 16 throw new RuntimeError('ignore this exception'); |
| 17 } |
| 18 replyTo.call('hello'); |
| 19 port.close(); |
| 20 }); |
| 21 } |
| 22 |
| 23 bool exceptionCallback(IsolateUnhandledException e) { |
| 24 return e.source.message == 'ignore this exception'; |
| 25 } |
| 26 |
| 27 void main() { |
| 28 var isolate_port = spawnFunction(entry, exceptionCallback); |
| 29 |
| 30 // Send a message that will cause an ignorable exception to be thrown. |
| 31 Future f = isolate_port.call('throw exception'); |
| 32 f.onComplete((future) { |
| 33 // Exception wasn't ignored as it was supposed to be. |
| 34 print('failed handling exception'); |
| 35 exit(1); |
| 36 }); |
| 37 |
| 38 // Verify that isolate can still handle messages. |
| 39 isolate_port.call('hi').onComplete((future) { |
| 40 if (future.exception != null) { |
| 41 print('unhandled exception: ${future.exception}'); |
| 42 exit(1); |
| 43 } |
| 44 if (future.value != 'hello') { |
| 45 print('unexpected response: ${future.value}'); |
| 46 exit(1); |
| 47 } |
| 48 exit(0); |
| 49 }); |
| 50 } |
| OLD | NEW |