diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-03-06 13:58:02 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-03-07 22:37:57 -0800 |
| commit | d7e74b5e91b0b6b6a5613f54479d2ef9fe9c392f (patch) | |
| tree | b1ce2f5b126be2790aad28ac0c0e526979d91e49 /doc/tutorial-tasks.md | |
| parent | 0ea031bcb8c237365b8bf15ae474972570cf15f9 (diff) | |
| download | rust-d7e74b5e91b0b6b6a5613f54479d2ef9fe9c392f.tar.gz rust-d7e74b5e91b0b6b6a5613f54479d2ef9fe9c392f.zip | |
librustc: Convert all uses of `assert` over to `fail_unless!`
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"); # } ~~~~ |
