より詳細な情報については、アサーション・エラー・タイプの種類を取得することにより

package main

import (
    "fmt"
    "os"
)

func main() {
    f, err := os.Open("/test.txt")
    if err, ok := err.(*os.PathError); ok {
        fmt.Println("File at path", err.Path, "failed to open")
        return
    }
    fmt.Println(f.Name(), "opened successfully")
}




おすすめ

転載: www.cnblogs.com/hualou/p/12069785.html