I searched but I don't find a solution for my answer.
My problem is the following : one of my library throw a ns::xml::C_Exception
when it does a check for a type. In another library, a class read a XML file for getting the configuration. And in the exec, I've got my try-catch with the correct type. But the exception isn't catch.
I checked the throw : I throw by value and :
try {
throw ns::xml::C_Exception ("mesg");
}
catch (const ns::xml::C_Exception& ex)
{
cout << ex.what () << endl;
}
Works.
If I use directly the check in the exec, this is the same as above, the exception is catched. But, when the C_Configuration
throw an exception, the catch doesn't work (and even the catch (...)
doesn't work).
For every try-catch block I used, this is the console output :
terminate called after throwing an instance of 'ns::xml::C_Exception'
what(): mesg
I also checked all the functions used : they all have the throw (ns::xml::C_Exception)
modifier.
C_Exception inherit directly from std::exception.
For testing, the C_Configuration always throws an exception :
bool
C_Configuration::load (string file)
{
// Useless code here
throw xml::C_Exception ("mesg");
// Useless code here
}
// In the header file :
bool
C_Configuration::reload (void)
{ return load (_file); }
And this is my main :
int
main (int argc, char** argv)
{
try {
C_Configuration c("test.xml");
c.reload ();
}
catch (const std::exception& ex)
{
cout << ex.what () << endl;
}
catch (...)
{
cout << "Oops" << endl;
}
// Useless code here.
return 0;
}
The related files (there are in my GitHub repo, so you can see the full sources) :
Thanks for you help.
Edit :
Compiler flags :
- For the exec :
-std=c++11
(plus the includes) - For the libraries :
-std=c++11 -fPIC
(plus the includes)
Linker flags :
- For the exec : Just the libraries and the library path.
- For the libraries :
-shared
EDIT : @ZanLynx said the problem comes from differents typeid between the two libraries. I merged the libraries into only one, but still the exception isn't caught.