2 错误处理

错误处理 — Comprehensive Rust

译文 · 基于 Comprehensive Rust

原文链接: https://google.github.io/comprehensive-rust/error-handling.html

2 错误处理

本小节约需 55 分钟。内容包括:

内容时长
Panic3 分钟
Result5 分钟
Try 运算符5 分钟
Try 类型转换5 分钟
Error Trait5 分钟
thiserror5 分钟
anyhow5 分钟
练习:用 Result 重写20 分钟

2.1 Panic

01-Panic — Comprehensive Rust

2.2 `Result`

02-Result — Comprehensive Rust

2.3 Try 运算符

03-Try 运算符 — Comprehensive Rust

2.4 Try 类型转换

04-Try 类型转换 — Comprehensive Rust

2.5 `Error` Trait

05-Error Trait — Comprehensive Rust

2.6 `thiserror`

06-thiserror — Comprehensive Rust

2.7 `anyhow`

07-anyhow — Comprehensive Rust

2.8 练习:用 `Result` 重写

练习:用 Result 重写 — Comprehensive Rust

最后修改 August 11, 2026: 更新 (70a5af133)