gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Allowing Applications to continue after exception...


From: David Chisnall
Subject: Re: Allowing Applications to continue after exception...
Date: Mon, 9 Mar 2009 13:55:03 +0000

On 22 Feb 2009, at 12:58, Richard Frith-Macdonald wrote:


On 22 Feb 2009, at 12:42, David Chisnall wrote:
It sounds like a good thing to have the option of resuming, even though it's generally not advisable.

Do you have a patch for gcc/libobjc which would allow that?

It won't require patching gcc, just libobjc. I don't have a patch currently, but I can probably create one fairly easily. It just requires adding an optional trampoline in the throw function that will bounce the exception out before unwinding the stack.

Yes please ... I'd love to try that out.

The same functionality, with a less elegant implementation, is provided by ETException. There are a couple of example use-cases in this paper:

http://www.swan.ac.uk/compsci/research/reports/2008/CSR14-2008.pdf

The current code in Étoilé allows exceptions to be either resumed or restarted. Restarting jumps back to the start of the exception- handling block and lets the code try again. This is currently done in a really messy way. Ideally I'd want to make sure that the compiler inserts an entry into the DWARF table pointing to the start of this block and then let the unwind library walk back up the stack to find it. This is a much bigger change, and one I won't have time to do for a little while.

I'm not sure about that ... it's certainly not needed by GNUstep and, while I can see the appeal, I can't think of any systems that actually allow re-execution of the 'try' block, so this would not fit into normal coding paradigms.

It's common in Lisp, and supported by a few Smalltalk systems.

What I'm really concerned about at the moment is trying to get code into the gcc distribution before the next release which would let me properly implement the Openstep/MacOS-X exception handling API when using objc native exceptions. It looks like that's just a function to set an uncaught exception handler.

Adding an uncaught exception handler is a bit different. This, in Cocoa, doesn't allow you to resume from the exception, it just lets you tidy up before the program exits. You can achieve exactly the same functionality without modifying the compiler or runtime by implementing your main function like this:

int main(int argc, char **argv)
{
        int ret = -1;
        @try
        {
                ret = retreal_main(argc, argv);
        }
        @catch (id e)
        {
                NSUncaughtExceptionHandler *h = NSGetUncaughtExceptionHandler();
                if (h != (NSUncaughtExceptionHandler*)0)
                {
                        h(e);
                }
        }
        return ret;
}

I believe you should be able to use GNUstep's existing fake main code for this. If you don't want to do this, then I could add a hack to the personality function to do something equivalent. Unfortunately, like most of the rest of GNU libobjc, the unwind code is typical GNU code, being an almost unreadable mess of #ifdefs with no clear separation of concerns in a coding convention designed for minimal readability. The version I'm using seems to be using GNUstep make and doesn't compile the exception handling stuff. I'll grab a copy of the trunk version and see if it's any better.

David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]