Created
June 14, 2015 02:11
-
-
Save indragiek/dd93cf3a721c3adce64a to your computer and use it in GitHub Desktop.
In response to: https://twitter.com/larcus94/status/609902438221418496
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
func crashOnError<T>(f: Void throws -> T) -> T { | |
do { | |
return try f() | |
} catch { | |
fatalError("Uncaught error") | |
} | |
} | |
enum TestError: ErrorType { | |
case AnError | |
} | |
func throwingFunction() throws { | |
throw TestError.AnError | |
} | |
crashOnError { try throwingFunction() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scratch that. Here's how to do it the short way: https://twitter.com/myell0w/status/609907058461151232