【发布时间】:2013-08-06 05:23:17
【问题描述】:
我正在使用mailcore2,它都是基于块的。通常他们会这样定义一个操作
SomeMailCoreOp *op = [session getOp];
[op start:^(NSError* error, id result) {
if (error) {
// handle error code
}
}];
所以我想做的基本上就是在每次遇到错误时抛出一个NSException。这样我就可以在我的代码库的其他地方捕获它。所以我为NSError创建了一个类别:
@implementation NSError (Addons)
-(NSString *)description {
return [NSString stringWithFormat:@"%@ - %@",
[self localizedDescription], [self localizedFailureReason]];
}
@end
这就是我通常处理错误的方式:
SomeMailCoreOp *op = [session getOp];
[op start:^(NSError* error, id result) {
if (error) {
[NSException raise:@"failure" format:[error description]];
}
}];
我认为这是有道理的,因为在documentation for NSException 他们得到了这个format:
format,人类可读的消息字符串(即异常 原因)与变量参数的转换规范 跟随。
但当我执行上述操作时,我总是会收到此编译器警告:
format string is not a string literal (potentially insecure)
我该如何解决这个问题?
【问题讨论】:
标签: iphone objective-c error-handling compiler-errors nserror