我有這個錯誤錯誤是 ParseInt 類型。如何檢查我假設我會使用errors.Is但不確定在這種情況下我將如何做的錯誤
1 回答

智慧大石
TA貢獻1946條經驗 獲得超3個贊
https://pkg.go.dev/[email protected]#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 關注
- 98 瀏覽
添加回答
舉報
0/150
提交
取消