Returning from a finally
block suppresses the propagation of any unhandled exception which was thrown in the try
or
catch
block.
Noncompliant code example
void openResource() {
@throw [NSException exceptionWithName:@"FileNotFoundException" reason:@"File Not Found on System" userInfo:nil];
}
void fun() {
@try {
openResource();
}
@finally {
closeResource();
return; // Noncompliant - prevents the exception from being propagated
}
}
Compliant solution
void openResource() {
@throw [NSException exceptionWithName:@"FileNotFoundException" reason:@"File Not Found on System" userInfo:nil];
}
void fun() {
@try {
openResource();
}
@finally {
closeResource();
}
}