Please explain DEFER's behaivour in golang : <p>As I know, defer is usually used to close or free resources.
And using <code>defer FUNC ()</code> inside the block (function) of the code ensures that <code>FUNC ()</code> will call in case of any return from this block(function) or panic in this block (function).</p>

<p>So - how to explain <code>defer</code> behavior in this code: (<a href="https://play.golang.org/p/FPA0wrRyw1f" rel="nofollow noreferrer">Example</a>):</p>

<pre><code>package main
import (
  "fmt"
  "errors"
)
func test() error {
  err := errors.New("some error")
  return err
}
func main() {
  if err := test(); err!=nil {
    fmt.Println("ERROR EXIT")
    return
  }
  defer fmt.Println("DEFER EXIT")
  fmt.Println("NORMAL EXIT")
}
</code></pre>

<p>I expected to see this:</p>

<pre><code>ERROR EXIT
DEFER EXIT
</code></pre>

<p>But got it:</p>

<pre><code>ERROR EXIT
</code></pre>

<p>Where am I wrong?</p>
