Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created October 11, 2018 04:24
Show Gist options
  • Save vialyx/2d92d00ff2d5dd331912b96f565e9b48 to your computer and use it in GitHub Desktop.
Save vialyx/2d92d00ff2d5dd331912b96f565e9b48 to your computer and use it in GitHub Desktop.
enum MachingError: Error {
case NotEnoughtCharacters(count: Int)
}
func throwingFunction(_ source: String) throws -> Bool {
let minCharacters = 5
guard source.count >= minCharacters else {
throw MachingError.NotEnoughtCharacters(count: minCharacters)
}
return true
}
do {
try throwingFunction("func")
} catch is MachingError {
print("MachingError")
}
// Converting Errors to Optional Values
try? throwingFunction("nil")
// Disabling Error Propagation
try! throwingFunction("source")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment