I'm using mailcore2 which is all block based. Typically they define an operation like so
SomeMailCoreOp *op = [session getOp];
[op start:^(NSError* error, id result) {
if (error) {
// handle error code
}
}];
So what I wanted to do is basically simply throw an NSException
every time an error is encountered.. so that I can catch it somewhere else in my code base.. So I created a category for NSError
:
@implementation NSError (Addons)
-(NSString *)description {
return [NSString stringWithFormat:@"%@ - %@",
[self localizedDescription], [self localizedFailureReason]];
}
@end
and this is how I would like to typically handle errors:
SomeMailCoreOp *op = [session getOp];
[op start:^(NSError* error, id result) {
if (error) {
[NSException raise:@"failure" format:[error description]];
}
}];
I thought this makes sense since in the documentation for NSException they got this for format
:
format, A human-readable message string (that is, the exception reason) with conversion specifications for the variable arguments that follow.
yet I always get this compiler warning when I do the above:
format string is not a string literal (potentially insecure)
how do I get around this?