• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dealing with exceptions in a drawing stack
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dealing with exceptions in a drawing stack


  • Subject: Re: Dealing with exceptions in a drawing stack
  • From: Graham Cox <email@hidden>
  • Date: Thu, 15 Jan 2009 16:21:48 +1100


On 15 Jan 2009, at 3:53 pm, Kyle Sluder wrote:

This is known as a "continuation".  Scheme, for example, often uses
them instead of exceptions.  Much like a jmp_buf, It contains all of
the information necessary to resume execution at the point the
continuation is created.  In the event of an error, an error handler
is invoked with the continuation object, at which point the error
handler can inspect the error condition and potentially modify the
state such that execution can continue to proceed.  It then executes
the continuation and the program resumes where it left off.


OK, interesting...



This isn't the model that exceptions follow, unfortunately.  By the
time your @catch block has caught the exception, the stack has already
been unwound and you can't get it back.


That's OK for the stack in general. The problem seems to be it leaves the graphics context stack out of whack. I can obviously deal with this by @catching wherever I have used saveGraphicsState and calling restoreGraphicsState in my catch block before rethrowing, but it's really clunky.

What I tried was this:

// at my very top level, i.e. [NSView drawRect:]

NSGraphicsContext* topContext = [[NSGraphicsContext currentContext] retain];

@try
{
// make all my other drawing calls, any of which might save/restore the graphics context but also could throw an exception


}
@catch( NSException* exc )
{
	// we're back at the top, just ignore the exception here
}

[NSGraphicsContext setCurrentContext:topContext];
[topContext release];


Which actually seems to work - the view is no longer screwed up and unusable following an exception. However, I'm not sure this is safe, as it's blowing away all the stacked graphics contexts. While that's what I want, I don't know if I'm allowed to just forget they ever existed in this way.


--Graham


_______________________________________________

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


  • Follow-Ups:
    • Re: Dealing with exceptions in a drawing stack
      • From: email@hidden
References: 
 >Dealing with exceptions in a drawing stack (From: Graham Cox <email@hidden>)
 >Re: Dealing with exceptions in a drawing stack (From: "Kyle Sluder" <email@hidden>)

  • Prev by Date: Re: what the hell is Error (1007) creating CGSWindow?
  • Next by Date: Re: What determines VSIZE allocation?
  • Previous by thread: Re: Dealing with exceptions in a drawing stack
  • Next by thread: Re: Dealing with exceptions in a drawing stack
  • Index(es):
    • Date
    • Thread