Last active
May 4, 2018 15:36
-
-
Save toddhopkinson/6e817b23fee4e49c4e1651086dd49c66 to your computer and use it in GitHub Desktop.
catch where clause
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mistakenly-trailing
)
near the end of line 22