| OLD | NEW |
| 1 --- | 1 --- |
| 2 layout: default | 2 layout: default |
| 3 title: "Futures and Error Handling" | 3 title: "Futures and Error Handling" |
| 4 description: "Everything you wanted to know about handling errors and | 4 description: "Everything you wanted to know about handling errors and |
| 5 exceptions when working with Futures (but were afraid to ask)." | 5 exceptions when working with Futures (but were afraid to ask)." |
| 6 rel: | 6 rel: |
| 7 author: shailen-tuli | 7 author: shailen-tuli |
| 8 has-permalinks: true | 8 has-permalinks: true |
| 9 article: | 9 article: |
| 10 written_on: 2013-03-07 | 10 written_on: 2013-03-07 |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 return new Future.sync(() { | 379 return new Future.sync(() { |
| 380 var x = someFunc(); // Unexpectedly throws in some rare cases. | 380 var x = someFunc(); // Unexpectedly throws in some rare cases. |
| 381 var y = 10 / x; // x should not equal 0. | 381 var y = 10 / x; // x should not equal 0. |
| 382 ... | 382 ... |
| 383 }); | 383 }); |
| 384 } | 384 } |
| 385 {% endprettify %} | 385 {% endprettify %} |
| 386 | 386 |
| 387 `Future.sync()` not only allows you to handle errors you know might occur, but | 387 `Future.sync()` not only allows you to handle errors you know might occur, but |
| 388 also prevents errors from *accidentally* leaking out of your function. | 388 also prevents errors from *accidentally* leaking out of your function. |
| 389 |
| 390 |
| 391 ## More information |
| 392 |
| 393 Read the following documentation for more details on using Futures: |
| 394 |
| 395 * [The Event Loop and Dart](/articles/event-loop/), |
| 396 an article that describes how to schedule tasks using Futures |
| 397 * [Future API reference](http://api.dartlang.org/dart_async/Future.html) |
| 398 |
| OLD | NEW |