Reputation: 199
Using the following method to get storyboard instance:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"storyboardName" bundle:nil];
I have noted that "If no storyboard resource file matching name exists, an exception is thrown with description: Could not find a storyboard named 'XXXXXX' in bundle....". I know it cannot be too careful to deal with the method.
My question is that is there any way to catch the exception and handle it manually. Any directions?
Upvotes: 1
Views: 425
Reputation: 97
UIStoryboard *st;
@try{
st = [UIStoryboard storyboardWithName:@"XXXXXX" bundle:nil];
}@catch (NSException *exception)
{
NSLog (@"%@",[exception description]);
return;
}
In this case if the storyboardWithName:@"XXXXXX" does not exist, then the code will go into the catch block where we can do the necessary handling manually. I have just logged the description of the exception. We can do any processing in that block without the code crashing
Upvotes: 1
Reputation: 1360
NSString *sbName = @"storyboardName";
UIStoryboard *sb;
@try {
sb = [UIStoryboard storyboardWithName:sbName bundle:nil];
}@catch (NSException *exception) {
[self warnMissingStoryBoard:sbName];
//handle here...
return;
}
//use sb here...
Upvotes: 1