diff options
Diffstat (limited to 'doc/tutorial-tasks.md')
| -rw-r--r-- | doc/tutorial-tasks.md | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index 52f63be984a..f5d3a482a9f 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -297,9 +297,9 @@ let result = ports.foldl(0, |accum, port| *accum + port.recv() ); Rust has a built-in mechanism for raising exceptions. The `fail!()` macro (which can also be written with an error string as an argument: `fail!( -~reason)`) and the `assert` construct (which effectively calls `fail!()` if a -boolean expression is false) are both ways to raise exceptions. When a task -raises an exception the task unwinds its stack---running destructors and +~reason)`) and the `fail_unless!` construct (which effectively calls `fail!()` +if a boolean expression is false) are both ways to raise exceptions. When a +task raises an exception the task unwinds its stack---running destructors and freeing memory along the way---and then exits. Unlike exceptions in C++, exceptions in Rust are unrecoverable within a single task: once a task fails, there is no way to "catch" the exception. @@ -339,7 +339,7 @@ let result: Result<int, ()> = do task::try { fail!(~"oops!"); } }; -assert result.is_err(); +fail_unless!(result.is_err()); ~~~ Unlike `spawn`, the function spawned using `try` may return a value, @@ -401,7 +401,7 @@ do spawn { // Bidirectionally linked // Wait for the supervised child task to exist. let message = receiver.recv(); // Kill both it and the parent task. - assert message != 42; + fail_unless!(message != 42); } do try { // Unidirectionally linked sender.send(42); @@ -507,13 +507,13 @@ do spawn { }; from_child.send(22); -assert from_child.recv() == ~"22"; +fail_unless!(from_child.recv() == ~"22"); from_child.send(23); from_child.send(0); -assert from_child.recv() == ~"23"; -assert from_child.recv() == ~"0"; +fail_unless!(from_child.recv() == ~"23"); +fail_unless!(from_child.recv() == ~"0"); # } ~~~~ |
