Re: Future Objective-C changes
Re: Future Objective-C changes
- Subject: Re: Future Objective-C changes
- From: Marcel Weiher <email@hidden>
- Date: Wed, 21 May 2003 15:24:04 +0200
I don't think so:
-(void)drawMyObject
{
[gc saveGraphicsContext];
NS_DURING
[self doStuffThatMightThrowExceptions];
NS_HANDLER
//-- exception we want to handle locally
NS_ENDHANDLER
[gc restoreGraphicsContext];
}
What happens if an exception is thrown that we *don't* want to handle
locally? We have to re-raise it, but before doing so, we have to
remember to restore the context..
-(void)drawMyObject
{
[gc saveGraphicsContext];
NS_DURING
[self doStuffThatMightThrowExceptions];
NS_HANDLER
//-- exception we want to handle locally
if(we don't want to handle locally)
{
[gc restoreGraphicsContext];
//re-raise the exception
}
NS_ENDHANDLER
[gc restoreGraphicsContext];
}
As evidenced by the fact that you left out a call [gc
restoreGraphicsContext], shows the usefulness of doing this
automatically.
Not in the least bit. I said it was *one* alternative, well aware that
there were others:
-(void)drawMyObject
{
id possibleException=nil;
[gc saveGraphicsContext];
NS_DURING
[self doStuffThatMightThrowExceptions];
NS_HANDLER
//-- exception we want to handle locally
possibleException=localException;
NS_ENDHANDLER
[gc restoreGraphicsContext];
[possibleException raise];
}
Still just one save/restore. Objects are good.
(1) Because it has nothing to do with the stack-frame (2) because you
are achieving the effect by *declaring a local variable*. Notice the
part about "declaring"...
Actually I'm "defining" a local variable,
Gosh, this sure looks like a declaration to me, and just strengthens my
point. How can I tell the difference by looking at the code? How is
the code intention-revealing?
and a defining local variable is nothing more than attaching some bit
of data to the local stack frame, so it has *everything* to do with
the local stack frame.
Exactly! *Declaring* the local variable has something to do with the
*local stack frame*. It has NOTHING whatsoever to do with modifying
*global* state.
On the other hand, the global graphics state has nothing to do with the
local stack-frame.
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.