Last active
August 29, 2015 13:59
-
-
Save mattn/10963262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os" | |
"syscall" | |
) | |
func main() { | |
f, err := os.Open("not-found-file.txt") | |
if err != nil { | |
switch t := err.(type) { | |
case *os.PathError: | |
switch t.Err { | |
case syscall.ENOENT: | |
log.Fatalf("ファイルが見つからなかったんだと思います: %v", t) | |
// 他のエラーとか... | |
default: | |
log.Fatalf("良く分からないエラーが発生しました: %v", t) | |
} | |
default: | |
log.Fatalf("もっと良く分からないエラーが発生しました: %v", t) | |
} | |
} | |
f.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment