Skip to content

Commit f7564c7

Browse files
committed
tutorial: Expand the failure section a bit
1 parent 0046aac commit f7564c7

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

doc/tutorial.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,9 @@ let (a, b) = get_tuple_of_two_ints();
782782
This will introduce two new variables, `a` and `b`, bound to the
783783
content of the tuple.
784784
785-
You may only use irrevocable patterns—patterns that can never fail to
786-
match—in let bindings, though. Things like literals, which only match
787-
a specific value, are not allowed.
785+
You may only use irrefutable patterns—patterns that can never fail to
786+
match—in let bindings. Other types of patterns, such as literals, are
787+
not allowed.
788788
789789
## Loops
790790
@@ -821,13 +821,29 @@ in a moment.
821821
## Failure
822822
823823
The `fail` keyword causes the current [task](#tasks) to fail. You use
824-
it to indicate unexpected failure, much like you'd use `exit(1)` in a
825-
C program, except that in Rust, it is possible for other tasks to
826-
handle the failure, allowing the program to continue running.
824+
it to indicate unexpected failure, much like you'd use `abort` in a
825+
C program or a fatal exception in a C++ program.
827826
828-
`fail` takes an optional argument, which must have type `str`. Trying
829-
to access a vector out of bounds, or running a pattern match with no
830-
matching clauses, both result in the equivalent of a `fail`.
827+
There is no way for the current task to resume execution after
828+
failure; failure is nonrecoverable. It is, however, possible for
829+
*another* task to handle the failure, allowing the program to continue
830+
running.
831+
832+
`fail` takes an optional argument specifying the reason for the
833+
failure. It must have type `str`.
834+
835+
In addition to the `fail` statement, the following circumstances cause
836+
task failure:
837+
838+
* Accessing an out-of-bounds element of a vector.
839+
840+
* Having no clauses match when evaluating an `alt check` expression.
841+
842+
* An assertion failure.
843+
844+
* Integer division by zero.
845+
846+
* Running out of memory.
831847
832848
## Assertions
833849

0 commit comments

Comments
 (0)