Created
January 9, 2017 20:08
-
-
Save nonsensery/89668e216adeed187cabe974069614d2 to your computer and use it in GitHub Desktop.
Swift-Objc try/catch bridge
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
objc_try_catch({ | |
let exception = NSException(name: "Something went wrong", reason: "not sure", userInfo: [:]) | |
print("raising NSException: \(exception)...") | |
exception.raise() | |
}) { exception in | |
print("... caught NSException: \(exception)") | |
} |
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
extern void objc_try_catch(__attribute__((noescape)) void(^tryBlock)(), __attribute__((noescape)) void(^catchBlock)(NSException *)); |
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
void objc_try_catch(__attribute__((noescape)) void(^tryBlock)(), __attribute__((noescape)) void(^catchBlock)(NSException *)) { | |
@try { | |
tryBlock(); | |
} | |
@catch (NSException *exception) { | |
catchBlock(exception); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment