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]

Re: Proxying between C++ exceptions and Java ones


>>>>> "Waba" == Waba  <waba-gcj@waba.be> writes:

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

Given that arbitrary C++ exceptions aren't easily representable in
Java, you probably just want to catch them and then throw some Java
exception (or ignore them).  In that case, I think this ought to work:

    try {
      random_cxx_function();
    } catch (...) {
      throw new SomeJavaException();
    }

Waba> I looked a bit at the gcc code, and from initialize_handler_parm in
Waba> gcc/cp/except.c, it seems that what really matters is that the two kinds
Waba> of catch clauses aren't mixed inside the same CU.

Yes.  As I understand it, this is an inherent limitation of GCC's
exception handling approach.

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

I think you need this line if you want to actually catch Java
exceptions in your CNI code.

Tom


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