Re: Exception handling when mixing C++ et C shared library.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry for the mail.

Forget it ;-)
Regards


Selon Laurent Marzullo <laurent@xxxxxxxxx>:

> 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
+

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux