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.
How can I \'catch\
First: You wouldn't want to do this. Try-catch-style error handling is no error handling. In Go you would check len(os.Args)
first and access element 1 only if present.
For the rare cases you need to catch panics (and your case is not one of them!) use defer
in combination with recover
. See http://golang.org/doc/effective_go.html#recover