week2

command
v0.0.0-...-12c6a5d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2022 License: MIT Imports: 5 Imported by: 0

README

  1. 我们在数据库操作的时候,比如 dao 层中当遇到一个 sql.ErrNoRows 的时候,是否应该 Wrap 这个 error,抛给上层。为什么,应该怎么做请写出代码?

回答:

应该Wrap这个error,因为dao层本身没法判断遇到sql.ErrNoRows后要怎么做(是结束程序,是再发一次查询请求,还是什么也不做)。所以按照 “If the error is not going to be handled, wrap and return up the call stack.” 的原则,要把额外的上下文如输入参数或失败的查询语句warp,为之后的处理排错提供依据。

数据库中内容: alt 数据库中内容

程序输出结果:

{sam 1}
2021/12/11 20:03:53 Query Id:2 not found!: sql: no rows in result set
exit status 1

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL