Re: try/catch/throw/finally example?
Re: try/catch/throw/finally example?
- Subject: Re: try/catch/throw/finally example?
- From: Chris Hanson <email@hidden>
- Date: Fri, 25 Aug 2006 19:39:28 -0700
On Aug 25, 2006, at 4:10 PM, Keith Ray wrote:
I noticed that even though the compiler doesn't complain about about a
missing catch block, if it *is* missing, the finally block is never
executed.
@try {
[stringOne appendString:stringTwo];
} @finally {
NSLog(@"This always happens.");
}
The compiler can't know if any particular message expression is going
to result in a thrown exception, because Objective-C neither has nor
requires exception specifications.
The compiler also can't know if an exception thrown out of the @try
block won't be caught by the caller of the method that contains the
above code, because the compiler can't deterministically know the
caller of any method.
On the other hand, the @finally block should always be executed. If
you encounter situations in which you write code like the above and
the @finally block isn't executed, you should definitely file a bug
with as close to a reproducible case as you can.
-- Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden