title: Catching panics in Golang
body: <p>With the following code, if no file argument is given, a panic is thrown for line 9 <code>panic: runtime error: index out of range</code> as expected.</p>
  
  <p>How can I 'catch' this panic and handle it when directly when passing something to it (<code>os.Args[1]</code>) that causes the panic? Much like try/catch in PHP or try/except in Python.</p>
  
  <p>I've had a search here on StackOverflow but I've not found anything that answers this as such.</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "os"
  )
  
  func main() {
      file, err := os.Open(os.Args[1])
      if err != nil {
          fmt.Println("Could not open file")
      }
      fmt.Printf("%s", file)
  }
  </code></pre>