Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread Quincey Morris
On Jan 19, 2009, at 14:54, Graham Cox wrote: Well, it's not really in an unsaveable state. The data model itself isn't damaged by exceptions thrown from the drawing code. However, the visual appearance of the document is badly upset (scrollbars suddenly disappear, rulers get drawn in the mi

Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread Graham Cox
On 20 Jan 2009, at 5:24 am, I. Savant wrote: On Jan 19, 2009, at 12:57 PM, Paul Bruneau wrote: I'm confused by it, since I have been directed in the past by people who know that The Cocoa Way is to have objects know how to draw themselves--via a category if desired. Is there differing op

Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread Paul Bruneau
On Jan 19, 2009, at 2:08 PM, Quincey Morris wrote: I don't get this at all (not just the quoted comments, but going all the way back to Graham's original statement). -- If a failure in the drawing code destroys the *data model* (thereby preventing it from being saved) then there's something

Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread Quincey Morris
On Jan 19, 2009, at 10:16, Shawn Erickson wrote: On Mon, Jan 19, 2009 at 9:57 AM, Paul Bruneau wrote: On Jan 19, 2009, at 2:49 AM, Kyle Sluder wrote: 3) You've over-architected your drawing code. Typically the fewer objects that are responsible for drawing (i.e. view objects) the better. S

Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread I. Savant
On Jan 19, 2009, at 12:57 PM, Paul Bruneau wrote: I'm confused by it, since I have been directed in the past by people who know that The Cocoa Way is to have objects know how to draw themselves--via a category if desired. Is there differing opinion on this? (apparently there is...) This

Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread Shawn Erickson
On Mon, Jan 19, 2009 at 9:57 AM, Paul Bruneau wrote: > On Jan 19, 2009, at 2:49 AM, Kyle Sluder wrote: > >> 3) You've over-architected your drawing code. Typically the fewer >> objects that are responsible for drawing (i.e. view objects) the >> better. Situations like the one you're describing o

Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread Paul Bruneau
On Jan 19, 2009, at 2:49 AM, Kyle Sluder wrote: 3) You've over-architected your drawing code. Typically the fewer objects that are responsible for drawing (i.e. view objects) the better. Situations like the one you're describing often arise from making model objects responsible for their own d

Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread Michael Ash
On Mon, Jan 19, 2009 at 6:07 AM, Graham Cox wrote: > What does appear to help a lot is saving the current context at the top of > the drawing stack and putting it back explicitly at the end (as per my > previously posted code snippet). If the save/restores are balanced, > effectively this is a no-

Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread Graham Cox
On 19 Jan 2009, at 6:49 pm, Kyle Sluder wrote: Well it sounds like there are a number of issues here: 1) You're throwing exceptions in drawing code. Even if you catch them so they don't screw up the draw stack, this will be extremely slow and have adverse effects on the drawing. My understa

Re: Dealing with exceptions in a drawing stack

2009-01-18 Thread Kyle Sluder
On Mon, Jan 19, 2009 at 2:32 AM, Graham Cox wrote: > Naturally I would prefer that no exceptions can ever be thrown in this code. > But the reality of development is, that yes, sometimes they do. Very often > this is from an NSAssert message which are liberally used throughout most of > the code.

Re: Dealing with exceptions in a drawing stack

2009-01-18 Thread Graham Cox
On 16 Jan 2009, at 8:33 pm, kyle.slu...@gmail.com wrote: What are you doing that could throw an exception? After all, exceptions are used to indicate programmer error, and are expensive to throw. Something tells me that you shouldn't be worrying about exceptions in your drawing code to begin

Re: Dealing with exceptions in a drawing stack

2009-01-16 Thread matt . gough
On 16 Jan 2009, at 10:33, kyle.slu...@gmail.com wrote: What are you doing that could throw an exception? After all, exceptions are used to indicate programmer error, and are expensive to throw. Something tells me that you shouldn't be worrying about exceptions in your drawing code to begin wi

Re: Dealing with exceptions in a drawing stack

2009-01-16 Thread kyle . sluder
What are you doing that could throw an exception? After all, exceptions are used to indicate programmer error, and are expensive to throw. Something tells me that you shouldn't be worrying about exceptions in your drawing code to begin with. --Kyle Sluder

Re: Dealing with exceptions in a drawing stack

2009-01-14 Thread Graham Cox
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 err

Re: Dealing with exceptions in a drawing stack

2009-01-14 Thread Kyle Sluder
On Wed, Jan 14, 2009 at 11:34 PM, Graham Cox wrote: > If an exception is thrown from somewhere down inside this stack, I'd prefer > it if I could continue to draw what can be drawn, rather than have to abort > the drawing altogether which usually leaves the whole view in a weird state > (at which

Dealing with exceptions in a drawing stack

2009-01-14 Thread Graham Cox
Suppose I have a drawing stack that is called from a view's drawRect: method. This stack can end up quite deep, with objects calling other objects to implement parts of their drawing. Some of these methods will save and restore the graphics context. If an exception is thrown from somewhere