When you catch an exception in an ObjC @catch
block, what is the lifecycle of that exception object? I know I can safely use it inside the block, but what if I want to use it again after the block, like this?
NSException * exception = nil;
@try {
// do something risky
} @catch(NSException * e) {
exception = e;
}
if (exception) {
NSLog(@"Caught exception: %@", exception);
}
Can I safely stash the reference into another local? Should I be retain, autorelease
ing it for safety? Can I retain it and hold onto it indefinitely?
(It does seem to work OK if I assign to the local, or retain and use later, but the docs don't really discuss where this object "comes from" in terms of ownership, or if it's special, so I was looking for more clarity.)