Skip to content
dreamcode
dreamcode
Back to map
Exceptions · Lesson 27 of 44
+15 XP on finish
PYTHON INTERMEDIATE

Exceptions

Use try and except blocks to handle exceptions. This prevents your program from crashing when a runtime error occurs.

How it reads
try: wraps the code that might fail at runtime
except ValueError: catches and handles specific ValueErrors
Cloud tip: Always catch specific errors (like ValueError or KeyError) instead of a generic Exception.
main.py
PYTHON
real Python, runs in your browser
CONSOLE
- run your code to see output -