I always thought using @try @catch in ObjC was considered bad practice (perhaps wrongly, or maybe rightly, but not anymore?). I've never used @try, @catch in an Objective-C app because I always thought, again perhaps wrongly, that exceptions thrown by the system (or a framework, or anyone) were to signify that you are now in an unrecoverable state? And I thought that the @try @catch stuff was kind of legacy stuff and we aren't really supposed to use that functionality of the language?
Looking at this bit of Apple sample code I see:
@try
{
NSViewController *vcToRemove = splitViewItem.viewController;
[vcToRemove removeObserver:self forKeyPath:@"touchBar" context:@"touchBar"];
}
@catch(id anException) {
//Do nothing, obviously it wasn't attached because an exception was thrown.
}
You don't see @try and @catch in Objective-C code often. Is doing this with KVO an "exception to the rule" and I was in the dark? Or have Objective-C best practices changed, and the new world order (nWo) is upon us?
Is this considered "good" now? I've seen a developer correct code like this saying something like "this is not java, please fix this." I would probably do the same. I just wanted to check in with the Apple Gods on this.
Thanks!