Re: @try @catch
Re: @try @catch
- Subject: Re: @try @catch
- From: "Michael Ash" <email@hidden>
- Date: Thu, 14 Aug 2008 10:50:17 -0400
On Thu, Aug 14, 2008 at 7:21 AM, Graham Cox <email@hidden> wrote:
>
> On 14 Aug 2008, at 8:58 pm, Georg Seifert wrote:
>
>> is it recommended to use @try .. @catch blocks as flow control like it is
>> used in Python. They say explicitly to use it rather than do a lot of test
>> before just try if it works to look after it only if it fails.
>
> Hmmm, I'll be looking forward to the replies to this question!
>
> My view is absolutely NOT to use try/catch for flow control. They were
> invented to handle exceptional conditions, and that's what they should be
> used for. They are not a substitute for proper conditional clauses and
> properly structured code. I believe the Python advice (which I take at face
> value, not being familiar with Python) is misguided at best, though may suit
> that language better. Also, my understanding is that while a try block is
> very cheap, the catch block is not. Since they are only expected to be run
> once in a blue moon, that's reasonable, but if they are used routinely,
> performance is likely to suffer.
In addition to performance and design considerations, there's one more
rather silly but somewhat significant problem with this pattern.
Namely, many Cocoa exceptions log the error to the console before
throwing, as an additional indicator that something went wrong. For
example, unrecognized selectors do this. If you hit one of these
cases, it will cause your app to log a lot of errors in his console
when something isn't really going wrong, which may confuse or at least
annoy the user.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden