A T!F function can only fail with F values, so ? can't pass up an error of a different
enum E. A plain T! function accepts any error (it converts to Err).
Wrong#
enum ReadErr { Missing }
enum AppErr { Bad }
fn read(): int!ReadErr = 1
fn run(): int!AppErr {
let x = read()?
x
}Fixed#
enum ReadErr { Missing }
enum AppErr { Bad }
fn read(): int!ReadErr = 1
fn run(): int!AppErr {
let x = read() else e => fail(Bad)
x
}Common causes#
- Two layers with their own error enums: map one to the other with
else e => fail(...). - If callers don't need to match the error, return plain
T!.