我有这个错误错误是 ParseInt 类型。如何检查我假设我会使用errors.Is但不确定在这种情况下我将如何做的错误
1 回答

智慧大石
TA贡献1946条经验 获得超3个赞
https://pkg.go.dev/strconv@go1.19.3#NumError
type NumError struct {
Func string // the failing function (ParseBool, ParseInt, ParseUint, ParseFloat, ParseComplex)
Num string // the input
Err error // the reason the conversion failed (e.g. ErrRange, ErrSyntax, etc.)
}
错误是 ParseInt 类型。
"ParseInt"是“失败函数”的名称,即返回错误的函数。实际的错误类型是*strconv.NumError。您可以像这样检查它和 func 名称:
if e, ok := err.(*strconv.NumError); ok && e.Func == "ParseInt" {
// do xyz
}
- 1 回答
- 0 关注
- 72 浏览
添加回答
举报
0/150
提交
取消