title: Defer block is not executed
body: <p>I have the following swift code executing in playground:</p>
  <pre><code>func A() {
      print (&quot;Hello&quot;)
      guard 1 == 2 else {
          return
      }
      defer {
          print (&quot;World&quot;)
      }
  }
    
  A()
  </code></pre>
  <p>I expected to see</p>
  <pre><code>Hello
  World
  </code></pre>
  <p>Instead only the <code>Hello</code> is printed. Why is this? What am I missing?</p>
  <p>Here is a better example:</p>
  <pre><code>enum MyError: ErrorType {
      case TriggerDefer
  }
  
  func throwsMyError() throws {
      let myzero = Int(arc4random_uniform(1))
      
      guard myzero &gt; 1 else {
          throw MyError.TriggerDefer
      }
  }
  
  func A() throws {
      try throwsMyError()
      
      defer {
          print (&quot;Hello World&quot;)
      }
  }
  </code></pre>
  <hr />
  <h2>As per the answers and comments, the correct way to do this (with an example) is</h2>
  <pre><code>enum MyError: ErrorType {
      case TriggerDefer
  }
  
  func throwsMyError() throws {
      let myzero = Int(arc4random_uniform(1))
  
      print(&quot;Hello&quot;)
  
      guard myzero &gt; 1 else {
          throw MyError.TriggerDefer
      }
  }
  
  func A() throws {        
      defer {
          print (&quot;World&quot;)
      }
       
      try throwsMyError()
  }
  </code></pre>
  <p>The output will now be</p>
  <pre><code>Hello
  World
  </code></pre>