Throw or Rethrow that Error?
Deal with that Error
Error handling in Swift has come a long way. But wait, there are throws
and rethrows
keywords? What's going on?
An in-depth look into the two types of closures, focussing on @escaping
and @nonescaping
closures.
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 11.4.1, and Swift 5.2.2
The example
Imagine a function that adds stuff to Strings
(This is a convoluted example, people!).
We are going to use the following CustomError
to make things clear
The requirements are that we have a function that takes a name and function that takes a String
and returns a String
. This function that we take, however, can throw an error. This leads to our outer function being able to return an error itself.
Already the language of outer function starts to get a little confusing. In steps the code snippet!