November 2017
Intermediate to advanced
264 pages
5h 45m
English
When, during a computation, several function calls return a Result type value, the handling of the error propagation through pattern matching can become quite tedious-each returned Result type value requires a match to differentiate between an Ok value and an Err value.
We had exactly such a situation in the input_number.rs program, where we read an input from the terminal and tried to parse it into an unsigned integer, both operations can fail.
The try! macro was specifically made in order to simplify such code and make error-handling more elegant and readable.
The try! macro can only be used from inside a function that returns a Result type value, so not from within the main() function. Also, it can only ...
Read now
Unlock full access