Python基础 · free preview

Exceptions and Context Managers

Raise your own exceptions, define custom exception classes, run cleanup with finally, and build context managers for setup-and-teardown work.

1. Overview

Overview

2. Raising Exceptions

Raising Exceptions

3. Custom Exception Classes

Custom Exception Classes

4. finally and Cleanup

finally and Cleanup

5. The with Statement's Protocol

The with Statement's Protocol

6. The contextlib Shortcut

The contextlib Shortcut

7. A Validated Loader

A Validated Loader

8. A Timing Context

A Timing Context

Practice this interactively

Free account · instant grading · spaced review that schedules itself.

Start this course for free