Macro try
macro_rules! try {
($expr:expr $(,)?) => { ... };
}
Unwraps a result or propagates its error.
The ? operator was added to replace try!
and should be used instead. Furthermore, try is a reserved word
in Rust 2018, so if you must use it, you will need to use the
raw-identifier syntax: r#try.
try! matches the given Result. In case of the Ok variant, the
expression has the value of the wrapped value.
In case of the Err variant, it retrieves the inner error. try! then
performs conversion using From. This provides automatic conversion
between specialized errors and more general ones. The resulting
error is then immediately returned.
Because of the early return, try! can only be used in functions that
return Result.
Examples
use io;
use File;
use *;
// The preferred method of quick returning Errors
// The previous method of quick returning Errors
// This is equivalent to: