A blog for technology, SEO tips, website development and open source programming.

Error Handling in Swift

1 839

When calling a method that may cause a failure, you normally pass it with an NSError object (as a pointer). If there is an error, the object will be set with the corresponding error. You then check if the error object is nil or not and respond to the error accordingly.
That’s how you handle errors in Swift 1.2.

Now you use do-catch statement to catch errors and handle them accordingly.
As you may notice, we’ve put a try keyword in front of the method call.
With the introduction of the new error handling model in Swift 2.0, some methods can throw errors to indicate failures. When we invoke a throwing method, you will need to put a try keyword in front of it.

Follow me on Instagram

1 Comment
  1. […] Error Handling in Swift […]

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More