fail(e) returns an error from the function. In a T! function e is a str message or an
Err; in a T!E function it must be a value of the error enum E.
Wrong#
fn check(n: int): int! {
if n < 0 { fail(n) }
n
}Fixed#
fn check(n: int): int! {
if n < 0 { fail("negative: {n}") }
n
}Common causes#
- Failing with a number or other plain value: wrap it in a message.
- A message in a
T!Efunction: fail with a variant ofEinstead, e.g.fail(Bad(n)).