知识卡片

普通读书笔记卡 · 743.d.2.b.7

错误接口取决于调用边界

理解等级:高级

库不能预知调用方要重试、恢复还是展示,应提供足够具体的错误,让调用者决定响应。应用需要聚合多个依赖并形成统一报告,动态错误类型往往更便利。选择应看边界:需程序化分类的业务结果仍可保留枚举,不因处于应用层就一律擦除类型。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 1. Types Libraries Versus Applications · 查看原书依据

      Libraries Versus Applications The final advice from the previous section included the qualification “…for error handling in applications.” That’s because there’s often a distinction between code that’s written for reuse in a library and code that forms a top-level application.11 Code that’s written for a library can’t predict the environment in which the cod

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Libraries Versus Applications》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u029-ch01-037)。 - 结论依据:原文在“Libraries Versus Applications”附近的定义、例子或代码支撑本卡核心说明:库不能预知调用方要重试、恢复还是展示,应提供足够具体的错误,让调用者决定响应。边界按已读前提解释;示例未执行。 - 原始内容:Libraries Versus Applications The final advice from the previous section included the qualification “…for error handling in applications.” That’s because there’s often a distinction between code that’s written for reuse in a library and code that forms a top-level application.11 Code that’s written for a library can’t predict the environment in which the cod