Skip to content

Instantly share code, notes, and snippets.

@toddhopkinson
Last active May 4, 2018 15:36
Show Gist options
  • Save toddhopkinson/6e817b23fee4e49c4e1651086dd49c66 to your computer and use it in GitHub Desktop.
Save toddhopkinson/6e817b23fee4e49c4e1651086dd49c66 to your computer and use it in GitHub Desktop.
catch where clause
enum LavaError: Error {
case LavaNotHotError
case LavaTooHotError
}
struct LavaSpecialResponseCode: Error {
enum ErrorKind: Int {
case missingParams
case badData
}
let message: String
let kind: ErrorKind
}
// ... elsewhere ...
do {
try fetchLavaResponse()
} catch LavaNotHotError {
// ...typical pattern
} catch where (error as? LavaSpecialResponseCode)?.kind == LavaSpecialResponseCode.ErrorKind.missingParams) {
// this demonstrates the catch where clause. This may be useful where your errors fall just outside of the first catch pattern above
}
// ... elsewhere
func fetchLavaResponse(completion:()->()) throws {
// request stuff
}
@KyLeggiero
Copy link

Mistakenly-trailing ) near the end of line 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment