LYR-SEM0138
a call that may throw without a 'try' mark
A call (or 'await', a loop over a throwing iterator or coroutine, a close) that may throw is not marked 'try', or stands to the left of a 'try' that marks only what follows it.
Explanation
Every place an error can leave from is marked: try f() propagates, try? f() makes the value optional, try! f() panics, and a try { … } block marks its whole body. The mark is required even where the function's throws covers the error, so propagation is visible where it happens. A mark covers the expression to its right: in a() + try b(), a() is not covered; write try a() + b().
Put try (or try?/try!) before the call, or move the mark to the start of the expression.
Wrong
enum Oops :: [Error] {
Bad;
fn message(): string { return "oops"; }
}
fn risky(): int throws Oops { return 1; }
fn f(): int throws Oops { return risky(); }
fn main(): void {
let _ = try? f();
}
Right
enum Oops :: [Error] {
Bad;
fn message(): string { return "oops"; }
}
fn risky(): int throws Oops { return 1; }
fn f(): int throws Oops { return try risky(); }
fn main(): void {
let _ = try? f();
}