LYR-PAR0051
a 'catch' clause on 'try?' or 'try!'
A try? or try! expression is followed by catch clauses.
Explanation
try? takes every error and gives null; try! takes every error and panics. Neither leaves an error for a clause to catch; the clauses belong to a plain try.
Write a plain try with the clauses, or drop the clauses.
Wrong
enum Oops :: [Error] { Bad; fn message(): string { return "oops"; } }
fn risky(): int throws Oops {
return 1;
}
fn main(): void {
let n = try! risky() catch (_) 0;
}
Right
enum Oops :: [Error] { Bad; fn message(): string { return "oops"; } }
fn risky(): int throws Oops {
return 1;
}
fn main(): void {
let n = try risky() catch (_) 0;
let _ = n;
}