Week 14 • Tuesday

Block 134: Exception Handling in Scripts

Write robust scripts that handle errors gracefully.

Concepts

Code Examples

See exercise below.

Exercise

Wrap a file reading function with try/except to handle FileNotFoundError and PermissionError separately. Write a custom InvalidDataError exception and raise it in a data validation function.

Homework

Describe the difference between finally and else blocks in a try statement. Wednesday