This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: CNI compile error
Weiqi Gao wrote:
> > /opt/gcc-3.0/include/g++-v3/bits/ostream.tcc:708: mixing C++ and Java
> > catches
> > in a single translation unit
> >
> > Any hints?
>
> Never mind.
>
> The GCC 3.0 manual answered my question, "You cannot mix Java and C++
> exceptions in the same translation unit."[1]
>
> [1] Richard Stallman, Using and Porting the GNU Compiler Collection,
> FSF, Boston, 14-June-2001, p.206
>
> The sample needs to be fixed, then.
Yes. Its important to #include <cni.h> before any C++ library includes.
This contains a pragma that sets the compiler to use the Java
EH personality for the current translation unit. The CNI sample code was
written before this requirement existed.
> I'm still trying to see what practical limitations this imposes on
> writing native methods. Is the following a fair accessment?:
>
> + No C++ classes that throws or catches (C++) exceptions (e.g.,
> std::cout) can be used in CNI/JNI native methods.
My understanding is that you can do this provided that both the throw and
the catch (and possibly, any frames in between) are compiled with the Java
EH mode, but you can't catch a C++ exception from a separatly compiled
C++ library. The workaround would be to do the C++ catch in a separate
source file which does not include cni.h, and call that from your CNI
source.
regards
[ bryce ]