title: Best way to handle errors from async closures in Swift 2?
body: <p>I'm using a lot of async network request (btw any network request in iOS need to by async) and I'm finding way to better handle errors from Apple's <code>dataTaskWithRequest</code> which not supports <code>throws</code>.</p>
  
  <p>I have code like that:</p>
  
  <pre><code>func sendRequest(someData: MyCustomClass?, completion: (response: NSData?) -&gt; ()) {
      let request = NSURLRequest(URL: NSURL(string: "http://google.com")!)
  
      if someData == nil {
          // throw my custom error
      }
  
      let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
          data, response, error in
  
          // here I want to handle Apple's error
      }
      task.resume()
  }
  </code></pre>
  
  <p>I need to parse my possible custom errors and handle possible connection errors from <code>dataTaskWithRequest</code>. Swift 2 introduced <code>throws</code>, but you can't throw from Apple's closure because they have no throw support and running async.</p>
  
  <p>I see only way to add to my completion block <code>NSError</code> returning, but as I know using <code>NSError</code> is old-style Objective-C way. <code>ErrorType</code> can be used only with throws (afaik).</p>
  
  <p>What's the best and most modern method to handle error when using Apple network closures? There is no way no use throws in any async network functions as I understand?</p>