在嘗試創建文件時,由于“文件名太長”,我遇到了 os.PathError。我想處理這種情況以做一些具體的事情。除了檢查 error.Error 返回字符串“文件名太長”之外,我該怎么做?
1 回答

慕村225694
TA貢獻1880條經驗 獲得超4個贊
該錯誤取決于系統,但在 unix 系統上,錯誤值為syscall.ENAMETOOLONG
if pe, ok := err.(*os.PathError); ok {
? ? if pe.Err == syscall.ENAMETOOLONG {
? ? ? ? log.Fatal("name really was too long")
? ? }
}
- 1 回答
- 0 關注
- 141 瀏覽
添加回答
舉報
0/150
提交
取消