Python基础 · 免费预览

异常与上下文管理器

抛出自己的异常,定义自定义异常类,用 finally 执行清理,并编写处理准备与收尾工作的上下文管理器。

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

进入交互式练习

免费注册 · 即时批改 · 自动安排间隔复习。

免费开始这门课