Last active
August 22, 2017 21:03
-
-
Save sgr-ksmt/d8d7dba92588c8e5b843 to your computer and use it in GitHub Desktop.
Swift : autoreleasepool + try
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
public func autoreleasepool(@noescape code: () throws -> ()) rethrows { | |
try { | |
var error: ErrorType? | |
autoreleasepool { | |
do { | |
try code() | |
} catch (let e) { | |
error = e | |
} | |
} | |
if let error = error { | |
throw error | |
} | |
}() | |
} |
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 doSomething { | |
do { | |
try autoreleasepool { | |
try ~~~~~ // ★ | |
} | |
} catch (let e) { | |
print(e) // ★'s error is caught here! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍