This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Probleme with G++, shared library and exception
- From: Laurent Marzullo <laurent at marzu dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 4 Jul 2007 14:39:54 +0200
- Subject: Probleme with G++, shared library and exception
Hello all,
I'm using g++ 3.4.6.
I've wrote a program which is linked against a shared library. This shared
library is not dlopened ... just linked against my prog.
The shared library define a C++ class as follow
class ErrorHandler
{
public:
...
virtual void fatalError( const XmlParsingException& ) = 0;
...
};
The shared library also define exception class:
class Exception
{
...
};
class RuntimeException : public Exception
{
...
};
class XmlParsingException : public RuntimeException
{
...
};
class DOMParser
{
public:
...
Document parseFile( const char* );
void setErrorHandler( ErrorHandler* );
ErrorHandler* getErrorHandler( void ) const;
};
The method parseFile will then call the error handler method (set when calling
'setErrorHandler' when any fatal error occured).
My program then define a concrete implementation of the ErrorHandler as follow:
class MyErrorHandler : public ErrorHandler
{
public:
...
virtual void fatalError( const XmlParsingException& excp )
{
// throw std::bad_cast()
throw XmlParsingException( p_excp );
}
...
};
and in the main part:
try
{
DOMParser parser;
parser.setErrorHandler( new MyErrorHandler() );
Document doc = parser.parserFile( "test1.xml" );
}
catch ( XmlParsingException& excp )
{
std::cerr << excp.what();
}
catch ( std::exception& excp )
{
std::cerr << excp.what();
}
catch ( ... )
{
std::cerr << "Unknown exception!\n";
}
But my program finished like this:
terminate called after throwing an instance of
'Gargoyle::XML::XmlParsingException'
Aborted
And if I replace XmlParsingException by std::bad_cast into the fatalError method
the message is:
terminate called after throwing an instance of 'std::bad_cast'
what(): St8bad_cast
Aborted
Could anyone explain why none of my catch bloc (even the catch(...)) is run in
such case ??
Thanks a lot every body for any help.
+--------------------+
+ Laurent Marzullo
+