Created
October 11, 2018 04:24
-
-
Save vialyx/2d92d00ff2d5dd331912b96f565e9b48 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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