Question about EH

Mike Stump
Tue Feb 22 19:43:00 GMT 2000

> From: Tom Tromey <>
> Date: 22 Feb 2000 13:57:01 -0700

> Recently I've been working on making Java exceptions work well with
> g++.  Currently, you can't `catch' a Java exception in a C++
> function

>   /* No exception table implies the old style mechanism, so don't check. */
>   if (exception_table != NULL
>       && __get_eh_table_language (exception_table) != EH_LANG_Java)
>     return NULL;

Well, this is a java issue.  If you want to find the g++ entries, you
will need to figure out a mapping between C++ and Java that you like,
and extend the Java matcher to handle the union case better.  I could
not find the java matcher...  so I can't say too much more about it.

> Is my understanding correct?


> If so, then it would seem that exceptions were designed so that a
> C++ function could not catch a Java (or any other sort of)
> exception.

No, that would be wrong.  The exceptions were designed so that this
would work.  Only the implementation would be wrong, if it doesn't.

> Is there a particular reason for this?

Incompleteness of implementation is the most likely cause.

> Is there a particular way I should proceed?

Sure.  Figure out what C++ things you want to catch, and extend the
java matcher to handle them.  You may need a object translator to
translate/import the C++ EH object to a Java object.

Likewise, going the other direction, we would need to extend the C++
matcher to catch Java things, and may need an object translator to
import a Java object for C++.

As for the encoding/meaning of the typeinfo stuff in C++, you're going
to have to dig it up, read it, or ask...  Code is in method.c/except.c
and tinfo* and inc/typeinfo if you want more complete access to the

If you start small "i" (the mangling for the `int' type in C/C++), and
just catch those in java (from a throw 1; in C++), you will get a feel
for it.  In fact, I'd even start smaller and do a untyped catch (catch
(...) in C++) in java, and see if you can at least stop off in java
land.  That should be easy enough to do.

Some of the harder things will be transcoding complex types and
figuring out exactly how far you want to go in understanding c++ types
in java land.  C++ at least has a extern "Java" to help us.

I look forward to the harder questions.

More information about the Gcc mailing list