With the following code, if no file argument is given, a panic is thrown for line 9 panic: runtime error: index out of range as expected.
panic: runtime error: index out of range
How can I \'catch\
Go is not python, you should properly check for args before you use it:
func main() { if len(os.Args) != 2 { fmt.Printf("usage: %s [filename]\n", os.Args[0]) os.Exit(1) } file, err := os.Open(os.Args[1]) if err != nil { log.Fatal(err) } fmt.Printf("%s", file) }