Skip to content

Instantly share code, notes, and snippets.

Last active Apr 16, 2018
What would you like to do?
Capture ObjC exceptions. From
#import <Foundation/Foundation.h>
@interface ObjC: NSObject
+ (BOOL)catchException:(void(^)(void))tryBlock error:(__autoreleasing NSError **)error;
#import "ObjC.h"
@implementation ObjC
+ (BOOL)catchException:(void(^)(void))tryBlock error:(__autoreleasing NSError **)error {
@try {
return YES;
@catch (NSException *exception) {
*error = [[NSError alloc] code:0 userInfo:exception.userInfo];
return NO;
/// Return a storyboard for the given name and bundle. Log a console error if not found.
private static func createStoryboard(name: String, bundle: Bundle) -> UIStoryboard? {
var storyboard: UIStoryboard? = nil
do {
try ObjC.catchException {
storyboard = UIStoryboard(name: name, bundle: bundle)
} catch {
print("🚨 Failed to create storyboard \(name): \(error)")
return storyboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment