82_Go基础_1_50 error
1 package main 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 func main() { 9 f, err := os.Open("test.txt") 10 if err != nil { 11 //log.Fatal(err) 12 fmt.Println(err) //open test.txt: no such file or directory 13 if ins, ok := err.(*os.PathError); ok { 14 fmt.Println(ins) 15 fmt.Println("1.Op:", ins.Op) // 1.Op: open 16 fmt.Println("2.Path:", ins.Path) // 2.Path: test.txt 17 fmt.Println("3.Err:", ins.Err) // 3.Err: The system cannot find the file specified. 18 } 19 return 20 } 21 fmt.Println(f.Name(), "打开文件成功。。") 22 23 }