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
- Raising an Error
- Catching with try/except
- The raises Annotation
- Cleanup with finally