This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Exception handling when mixing C++ et C shared library.
- From: Laurent Marzullo <laurent at marzu dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 19 Jul 2007 13:43:09 +0200
- Subject: Re: Exception handling when mixing C++ et C shared library.
- References: <1184844463.469f4aaf04049@ssl0.ovh.net>
Sorry for the mail.
Forget it ;-)
Regards
Selon Laurent Marzullo <laurent@marzu.org>:
> Hello,
>
> I've got a shared library (gcdk) using libxml2 shared library and a program
> using gcdk, and the program terminate with the following error:
>
> terminate called after throwing an instance of 'std::bad_cast'
> what(): St8bad_cast
>
>
> Here the schema of the different call happening
>
> // libgcdk.so
>
> void
> libxml2_gcdk_error_handler_adapter( void* ctxt , xmlError* error )
> {
> ...
> throw XmlException();
> ...
> }
>
>
> Document
> LibXml2DOMParser::parseFile( const char* p_filename )
> {
> ...
> try
> {
> xmlParseDocument( ctxt ); // Parse the xml file
> // and call the function above in case of
> // error
> }
> catch ( XmlException const& p_excp )
> {
> // This catch block is working well as it catch the XmlException
> // thrown by the function libxml2_gcdk_error_handler_adapter.
> throw std::bad_cast();
> }
> }
>
>
> The main program the call the LibXml2DOMParser::parseFile method.
> The catch block inside this last method catch the XmlException but the catch
> block inside the main program does not catch the std::bad_cast exception.
>
> Do you known what happen ?
>
> in the main function, I do something like this:
>
> try
> {
> parser->parseFile( "test-document.xml" );
> }
> catch ( XmlException const& p_excp )
> {
> std::cerr << p_excp.what();
> }
> catch ( std::exception const& p_excp )
> {
> std::cerr << p_excp.what();
> }
> catch ( ... )
> {
> std::cerr << "Unknown exception.\n";
> }
>
> none of the catch block above is working ! And no matter the exception throw
> in
> the catch block of the parseFile method above ! (the libxml2 library is
> compiled with the -fexceptions compilation option).
>
> g++ 3.4.6
>
> Any hint please ?
> Thanks a lot.
>
+--------------------+
+ Laurent Marzullo
+