【发布时间】:2011-04-26 21:57:18
【问题描述】:
我(正如你们中的一些人从我的其他问题中知道的那样 :))正在构建一个 cocoa-touch 静态库,我将代码 [NSException raise:@"This is the name of my exception" format:@"This is my format", nil] 作为子类化 NSException 的快捷方式分散在我的整个项目中。这又回来咬我了,因为我只需要捕获名称中包含特定字符串的异常,然后让其他人过去。
现在我知道,如果我将 NSException 子类化,我可以这样做:
@try {
NSLog(@"This is some code that might raise an exception");
}
@catch (MyException *e){
NSLog(@"Yep, something went wrong....%@", e);
}
@finally {
NSLog(@"This is my cleanup code");
}
但是有没有比重构所有代码更简单的方法呢?
【问题讨论】:
标签: objective-c exception-handling try-catch