@@ -13,7 +13,7 @@ cheaper to create than traditional threads, Rust can create hundreds of
1313thousands of concurrent tasks on a typical 32-bit system.
1414
1515Tasks provide failure isolation and recovery. When an exception occurs in Rust
16- code (as a result of an explicit call to ` fail ` , an assertion failure, or
16+ code (as a result of an explicit call to ` fail!() ` , an assertion failure, or
1717another invalid operation), the runtime system destroys the entire
1818task. Unlike in languages such as Java and C++, there is no way to ` catch ` an
1919exception. Instead, tasks may monitor each other for failure.
@@ -296,9 +296,9 @@ let result = ports.foldl(0, |accum, port| *accum + port.recv() );
296296
297297# Handling task failure
298298
299- Rust has a built-in mechanism for raising exceptions. The ` fail ` construct
300- (which can also be written with an error string as an argument: `fail
301- ~ reason` ) and the ` assert` construct (which effectively calls ` fail` if a
299+ Rust has a built-in mechanism for raising exceptions. The ` fail!() ` macro
300+ (which can also be written with an error string as an argument: `fail!(
301+ ~ reason) ` ) and the ` assert` construct (which effectively calls ` fail!() ` if a
302302boolean expression is false) are both ways to raise exceptions. When a task
303303raises an exception the task unwinds its stack---running destructors and
304304freeing memory along the way---and then exits. Unlike exceptions in C++,
@@ -313,7 +313,7 @@ of all tasks are intertwined: if one fails, so do all the others.
313313# fn do_some_work() { loop { task::yield() } }
314314# do task::try {
315315// Create a child task that fails
316- do spawn { fail }
316+ do spawn { die!() }
317317
318318// This will also fail because the task we spawned failed
319319do_some_work();
@@ -337,7 +337,7 @@ let result: Result<int, ()> = do task::try {
337337 if some_condition() {
338338 calculate_result()
339339 } else {
340- fail ~"oops!";
340+ die!( ~"oops!") ;
341341 }
342342};
343343assert result.is_err();
@@ -354,7 +354,7 @@ an `Error` result.
354354> *** Note:*** A failed task does not currently produce a useful error
355355> value (` try ` always returns ` Err(()) ` ). In the
356356> future, it may be possible for tasks to intercept the value passed to
357- > ` fail ` .
357+ > ` fail!() ` .
358358
359359TODO: Need discussion of ` future_result ` in order to make failure
360360modes useful.
@@ -377,7 +377,7 @@ either task dies, it kills the other one.
377377# do task::try {
378378do task::spawn {
379379 do task::spawn {
380- fail ; // All three tasks will die.
380+ die!() ; // All three tasks will die.
381381 }
382382 sleep_forever(); // Will get woken up by force, then fail
383383}
@@ -432,7 +432,7 @@ do task::spawn_supervised {
432432 // Intermediate task immediately exits
433433}
434434wait_for_a_while();
435- fail ; // Will kill grandchild even if child has already exited
435+ die!() ; // Will kill grandchild even if child has already exited
436436# };
437437~~~
438438
@@ -446,10 +446,10 @@ other at all, using `task::spawn_unlinked` for _isolated failure_.
446446let (time1, time2) = (random(), random());
447447do task::spawn_unlinked {
448448 sleep_for(time2); // Won't get forced awake
449- fail ;
449+ die!() ;
450450}
451451sleep_for(time1); // Won't get forced awake
452- fail ;
452+ die!() ;
453453// It will take MAX(time1,time2) for the program to finish.
454454# };
455455~~~
0 commit comments