LYR-SEM0030
a thrown, declared or caught type that is not an Error
A throw throws a value, a throws clause lists a type, or a catch names a type that does not conform to Error.
Explanation
What is thrown is an Error: a struct, class or enum that conforms to Error (with its fn message(): string), an interface value of one, or a type parameter constrained to it. A number or a string is not thrown.
Declare an error type with :: [Error] and throw, declare and catch that.
Wrong
fn f(): int throws {
throw 5;
}
fn main(): void {
let _ = try? f();
}
Right
enum Oops :: [Error] { Bad; fn message(): string { return "oops"; } }
fn f(): int throws Oops {
throw Oops.Bad;
}
fn main(): void {
let _ = try? f();
}