EH in C (was: Re: (lack of) Thread-safe exceptions on AIX (gcc-2.95.1)

Geoff Keating
Tue Feb 1 15:37:00 GMT 2000

Zack Weinberg <> writes:

> On Tue, Feb 01, 2000 at 02:05:59AM -0800, Bill Tutt wrote:
> > 
> > The annoying thing is that C based try/catch handlers need some kind of
> > information about the exception that occurred if they want to do any
> > useful processing. So if the C based try/catch handlers can't catch
> > asynchrnous exceptions (segv, divdie by zero, etc) and information about
> > C++ based exceptions is kind of useless is there any reason we need
> > try/catch for C at all? i.e. can we get away with just a try/finally pair?
> > This avoids the GetExceptionCode() problem altogether, but leaves
> > AbnormalTermination(), but that seems like a fairly simple gcc builtin to
> > code up.
> The usual reason people want exceptions in C is to make pthread
> cancellation play nice with C++.  The pthread library has 'cleanups'
> that happen when a thread is cancelled, that are basically
> try/finally, but they don't interoperate with the C++ exception
> mechanism.  What you'd like is for pthread_cleanup_push/pop to be
> implemented in terms of try/catch, and pthread_cancel to throw an
> exception in the cancelled thread.
> That requires only try { } catch (...) { }, plus some way to throw
> an object (not just rethrow), in C.

Is there some reason why pthread_cleanup_push/pop can't be implemented
in C++ (with 'extern "C"', of course)?

It strikes me that there's no point modifying the C compiler until it
has most of the feature set of the C++ compiler, because we already
have such a thing called 'g++'.  And look, you get templates and
operator overloading for free! :-)

- Geoffrey Keating <>

More information about the Gcc mailing list