The raises Annotation
Mark functions that can fail.
Honest About Failure
Mojo wants functions to be honest about whether they can fail. The raises keyword marks a function that might raise an error. 📣
Adding raises
Put raises right after the argument list. It tells callers this function may not always succeed.
fn parse(text: String) raises -> Int:
...All lessons in this course
- Raising an Error
- Catching with try/except
- The raises Annotation
- Cleanup with finally