Lyricdev
GitHub

LYR-SEM0141

an error type caught twice by one 'try'

error ยท spec 06-errors

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;
    }
}
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;
    }
}