title: Go: returning from defer
body: <p>I want to return an error from a function if it panics (in Go):</p>
  
  <pre><code>func getReport(filename string) (rep report, err error) {
      rep.data = make(map[string]float64)
  
      defer func() {
          if r := recover(); r != nil {
              fmt.Println("Recovered in f", r)
              err, _ = r.(error)
              return nil, err
          }
      }()
      panic("Report format not recognized.")
      // rest of the getReport function, which can try to out-of-bound-access a slice
      ...
  } 
  </code></pre>
  
  <p>I appear to have misunderstood the very concept of panic and defer. Can anybody enlighten me?</p>