Exception 的其他用法

1
2
3
4
5
6
7
8
9
10
11
12
13

NSMutableDictionary *dict = @{}.mutableCopy;
NSString *name = nil;
@try {
[dict setObject:name forKey:@"name"];
} @catch (NSException *exception) {
NSString *reason = exception.reason;
NSMutableString *badKey = [reason componentsSeparatedByString:@":"].lastObject.mutableCopy;
[badKey.mutableCopy substringToIndex:badKey.length-2];
NSLog(@"badKey:%@", badKey);
} @finally {
NSLog(@"%@", dict);
}