知识卡片
错误结构保留操作上下文
PathError用Op、Path和Err保存操作名、路径及底层错误,Error() string负责可读描述。返回error接口让不同实现共用一个入口,需要结构化信息时再按类型或受支持接口提取;比较文本会丢失这种结构。类图对应原书os.PathError声明,当前所在包或别名布局需按版本查证。
结构图:
classDiagram
class error {
<<interface>>
Error() string
}
class PathError {
Op string
Path string
Err error
Error() string
}
PathError ..|> error : 指针方法满足
PathError o-- error : Err保存底层错误
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 流程控制方法 · 查看原书依据
type PathError struct { Op string // "open", "unlink", etc. Path string // The associated file. Err error // Returned by the system call. }
参考来源
- 位置:《Go并发编程实战》第04章《流程控制方法》之《4.3 异常处理》(来源项目book-sources;源文件:extracted/Go并发编程实战/_epub-src/text/part0000_split_030.html)
- 结论依据:原文围绕错误结构保留操作上下文给出定义、实例或限制;卡片结合这些上下文解释条件,已知错误在正文就近校正。
- 原始内容:type PathError struct { Op string // "open", "unlink", etc. Path string // The associated file. Err error // Returned by the system call. }