throwing C++ exceptions across C frames

Ben Liblit liblit@eecs.berkeley.edu
Tue Dec 31 02:55:00 GMT 2002


I am working with a mixed C/C++ code base.  Occasionally, the C++ code 
may want to throw an exception.  If there are only C++ function calls on 
the stack between the "throw" and the "catch", then the exception is 
caught properly.

However, if...

	- the C++ "catch" code calls some C function
	- this C function then calls back into C++ code
	- this C++ code now throws an exception

...then the exception is not caught and the program aborts as though it 
had run into an uncaught exception.  It appears as though stack 
unwinding and exception dispatch will not cross over a C stack frame.

Is there any possible way to make this work?  I realize that lobbing 
exceptions over the top of unsuspecting C code is questionable anyway, 
but this is a large existing code base and I don't have the option of, 
say, reworking everything in C++.

I am using gcc-3.2, g++-3.2, libstdc++-3.2, and glibc-2.2.93 on a Red 
Hat Linux 8.0 box.  Example code follows.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cxx.cc
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20021231/a9c23f10/attachment.cc>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: c.c
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20021231/a9c23f10/attachment.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Makefile
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20021231/a9c23f10/attachment.ksh>


More information about the Gcc mailing list