0Pricing
Mojo Academy · Lesson

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

  1. Raising an Error
  2. Catching with try/except
  3. The raises Annotation
  4. Cleanup with finally
← Back to Mojo Academy