本頁尚未翻譯,以下為英文原文。
#E0062: error not handled
A call can throw, and the error is neither caught nor declared. Mark the call with try, then either catch the error or add it to the enclosing function's throws.
nabi
let n = "42".parse::<i32>();
error[E0062]: this call can throw `ParseError` and must be marked with `try` (`try f()`; `try? f()` / `try! f()` to drop / panic on the error) --> main.nabi:1:9 | 1 | let n = "42".parse::<i32>(); | ^^^^^^^^^^^^^^^^^^^
Mark the call with try, and declare throws where the error goes on:
nabi
fn parse_n(s: str) throws -> i32 {
try s.parse::<i32>()
}
println(f"{try parse_n("42")}");
42
try? f() turns the error into none, and try! f() panics on it (chapter 10).
Related: E0063 thrown value is not an Error, E0064 optional operator on a value that is not optional, E0096 try or catch that does nothing
Found a mistake? Edit this page on GitHub. Last updated