[Openmcl-devel] fragile GUI Programming: Unhandled exception 10

Alexander Repenning ralex at cs.colorado.edu
Fri Oct 30 12:16:06 PDT 2009

On Oct 30, 2009, at 7:32 AM, Gary Byers wrote:
> On Fri, 30 Oct 2009, Alexander Repenning wrote:
> If instead of providing that information you're simply noting that
> "crashing is bad", for once I'm in full agreement with you.


> Since I don't know how to ensure that that cleanup will occur in
> the event of a non-local exit, one approach to being able to have
> errors in #/drawRect: methods and live to tell about it is to  
> establish
> a restart in the #/drawRect: method and transfer control to it in case
> of error:
> (objc:defmethod (#/drawRect: :void) ((self some-view) (rect #>NSRect))
>  (with-simple-restart (abandon-drawing "Stop trying to draw in ~s"  
> self)
>    (progn
>      ...
>      (if (zerop (random 10))
>        (error "You're number's up.")
>        (do-some-drawing ...)))))

This works quite nicely, thanks! The overhead is < 1 us which is  
essentially nothing for something like draw which has a general  
overhead of almost 1ms even on a fast intel-mac. I tried handler-case  
which did work too but did not allow the developer to poke around in  
the call stack.

> In practice, I think that in (most ? all ?) of the cases where I've
> had errors in event handlers it was indeed possible to simply
> abandon the event.

You must be programming different things. We end up with most cases  
NOT working.

> It's certainly reasonable to expect lisp-like behavior from lisp
> code; it's less reasonable to expect that kind of behavior from
> ObjC code, and recovering from errors on the event thread requires
> either the cooperation of both kinds of code or at least some
> basic awareness of the issues on the part of the developer.  I
> don't think that it's possible to get ObjC code that wasn't
> written with error recovery in mind to cooperate with the
> error recovery process; I can't imagine what that'd mean.

The restart approach you suggested works well, i.e., we do not have to  
rely on Objective-C to play nicer. It is pretty reasonable to wrap up  
handlers with this kind of restart functionality and only needs to be  
done at some strategic places to cover most of the cases.

Thanks Gary,  Alex

Prof. Alexander Repenning

University of Colorado
Computer Science Department
Boulder, CO 80309-430

vCard: http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20091030/3ceec940/attachment.htm>

More information about the Openmcl-devel mailing list