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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Proxying between C++ exceptions and Java ones


Hello,

I'd like to call C++ functions from a Java native method (implemented
through CNI). These functions may throw (C++) exceptions, so unless I
catch them in some way, the stack will keep unwinding and my program
will die. However, I am not supposed to mix C++ and Java exceptions
inside the same compilation unit, the documentation says.

I could of course make another proxy for this class, that catches any
C++ exception and uses return codes instead, but that isn't very nice,
especially since the Java class is already some kind of proxy to the C++
class. Is there any clever way ?

I looked a bit at the gcc code, and from initialize_handler_parm in
gcc/cp/except.c, it seems that what really matters is that the two kinds
of catch clauses aren't mixed inside the same CU. I thought that this
was solving my problem, since I would have been able to do:

  try { /* C++-throwing code */ } 
  catch (/* C++ exception */) { throw new SomeJavaException (...); }

However, <gcj/javaprims.h>, included from any java header, contains
the #pragma GNU java_exceptions, actually forcing the Java-Exc mode
inside any CU that handles Java objects. Commenting out this line makes
my trivial test program work perfectly, although this doesn't mean
anything.

Is this line useful ? Should it be removed ? Or am I just completely off
the track ?

Many thanks,
-Waba.


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