This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Proxying between C++ exceptions and Java ones
- From: Tom Tromey <tromey at redhat dot com>
- To: Waba <waba-gcj at waba dot be>
- Cc: java at gcc dot gnu dot org
- Date: 04 Mar 2005 16:55:12 -0700
- Subject: Re: Proxying between C++ exceptions and Java ones
- References: <20050303162258.GC11304@waba.be>
- Reply-to: tromey at redhat dot com
>>>>> "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