This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Question about EH


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,
which makes writing a CNI (Java native) function painful in some
situations: you must write a Java trampoline function which handles
the `catch'.

My current understanding is that at runtime a type matcher is called
to decide whether or not a given exception can be handled by a given
`catch' clause.

When exception tables are generated, each table has a type, and the
exception matchers fail if the table type doesn't match their expected
type.  For instance, the Java matcher starts like this:

  /* 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;

When I look in gcc/except.c, it seems that there is a single type (for
every function in a given translation unit.  From gcc/except.c:

    static short language_code = 0;

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.

Is there a particular reason for this?

Is there a particular way I should proceed?  All I really want is to
be able to write:

  try { ... }
  catch (java_type_here *foo) { ... }

in C++ and have it work as expected.  I'm not concerned about corner
cases (for example where one catch catches a Java type and the next
catches a non-Java type) -- these can just be errors.

Tom

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]