0Pricing
Mojo Academy · Lesson

Catching with try/except

Recover from a failure gracefully.

Catching the Fall

Raising signals a problem, but someone must catch it. Mojo uses a try block to run risky code and recover if it fails. 🪤

The try Block

Code that might fail goes inside try. If it raises, Mojo jumps straight to the matching recovery code below.

try:
    risky_step()

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