[Openmcl-devel] objc exception handling

Gary Byers gb at clozure.com
Sun Feb 23 16:07:01 PST 2003



On Sun, 23 Feb 2003, Yannick Versley wrote:

> When a (native) Objective-C class raises an exception (for instance with
> [ (@ "string" ) "foobar" ] when there is no method "foobar"), OpenMCL just
> exits after the error has been logged. It would be much more comfortable
> (and less frustrating too) if we could intercept these objc exceptions
> and raise a condition that could then be handled with normal mechanisms.
>

There seem to be several ways in which lisp and ObjC error handling
need to be better integrated:

 1) A lisp error in code called from ObjC (especially when called as part
of the ObjC event-dispatching mechanism) should ideally not interfere with
that event-dispatching mechanism.  I think that any behavior like trying
to enter a break loop in the main event dispatching thread counts as
interfering with event-dispatching.  It may be that the best that can
be done in cases like this is to (somehow) log an error message, cause
the event-handling thread to believe that the current event's been handled,
and let it go process the next event.

 2) An ObjC runtime error (missing/misspelled method or class name) that
happens in the event-dispatching thread probably needs to be treated in
much the same way: the lisp does need to hook into the ObjC exception-
notification system somehow, but once it's intercepted an ObjC exception
and mapped it to some lisp condition we seem to be back to case (1).

 3) An ObjC runtime error that happens in some other thread (e.g., typing
some code into a listener and not involving the event-dispatching thread)
-probably- can just be handled as if it were a non-fatal lisp error.

(2) and (3) imply that we need to intercept ObjC exceptions; (1) and (2)
imply that we probably have very limited ability to deal with any type
of error in the event-handling thread, but may be able to "recover" in
some crude way.  If (for instance) there's a typo in a "drawRect:" method
for some view, it's arguably better to get a flurry of messages to that
effect and still have the opportunity to correct the method definition
than to simply terminate the application.

> Normal exception handling in ObjC works using _setjmp/_longjmp in
> conjunction with NSAddHandler/NSRemoveHandler. Is it possible to use
> _setjmp with lisp code?

I think that there may be a bit more to ObjC exception handling than
_setjmp/_longjmp; I've stepped through some code in -[NSApplication run]
that seemed to be doing something like HANDLER-CASE.  I don't know what
would be involved in integrating ObjC's exception handling with lisp's,
but Apple's Java, AppleScript, FScript, and something called Joy (don't
have the URL handy) all integrate themselves into the ObjC exception
signalling/handling machinery in some mostly reasonable way (and all
of these environments have somewhat different exception models.)


>
> Thanks,
> Yannick Versley
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/cgi-bin/mailman/listinfo/openmcl-devel
>
>


_______________________________________________
Openmcl-devel mailing list
Openmcl-devel at clozure.com
http://clozure.com/cgi-bin/mailman/listinfo/openmcl-devel



More information about the Openmcl-devel mailing list