Probleme with G++, shared library and exception
Laurent Marzullo
laurent@marzu.org
Wed Jul 4 12:40:00 GMT 2007
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
+
More information about the Gcc-help
mailing list