LYR-SEM0141
an error type caught twice by one 'try'
Two 'catch' clauses of one 'try' name the same error type.
Explanation
The clauses of a try are tried in order, and the first whose type matches takes the error. A second clause for the same type can never run.
Remove one of the clauses, or merge their bodies.
Wrong
enum Oops :: [Error] {
Bad;
fn message(): string { return "oops"; }
}
fn risky(): int throws Oops { return 1; }
fn main(): void {
try {
let _ = risky();
} catch (_: Oops) {
return;
} catch (_: Oops) {
return;
}
}
Right
enum Oops :: [Error] {
Bad;
fn message(): string { return "oops"; }
}
fn risky(): int throws Oops { return 1; }
fn main(): void {
try {
let _ = risky();
} catch (_: Oops) {
return;
}
}