Rethrows
A function that takes a throwing closure as a parameter has to make a choice: either catch every error, or be a throwing function itself.
Let’s say you want a utility function to perform a certain movement, or set of movements, several times in a row. You could define this function as follows:
func perform(times: Int, movement: () throws -> ()) rethrows { for _ in 1...times {
try movement()
}
}
Notice the rethrows here. This function does not handle errors like moveSafely, but instead leaves the error handling up to the caller of the function, like goHome. By using rethrows instead of throws, this function indicates that it will only rethrow errors thrown by the function passed into it, but never errors of its own.