Lyricdev
GitHub

LYR-RT0010

try! on an error

panic ยท spec 06-errors

try! f() met an error. The panic carries the error's message; use try and let the error propagate, or catch it, where it can happen.

Program

class Boom :: [Error] {
    fn message(): string {
        return "boom";
    }
}

fn risky(fail: bool): int throws Boom {
    if (fail) {
        throw Boom { };
    }
    return 42;
}

fn main(): void {
    let n = try! risky(true);
    assert(n == 42);
}