I have the following sample code that throws a std::ios_base::failure
and tries to catch it, using clang 4.0 in c++11 mode:
#include <ios>
#include <iostream>
#include <stdexcept>
int
main()
{
try {
throw new std::ios_base::failure( "Bonkers" );
}
catch( std::ios_base::failure &e ) {
std::cout << "Failure " << e.what() << std::endl;
}
catch( ... ) {
std::cout << "Anything" << std::endl;
}
return 0;
}
I compile the program like this:
clang++-4.0 --std=c++11 -g -W -Wall ex.cc -o ex
And I get the output:
Anything
I would have expected for it to catch the specific exception. I tried the same with g++ 5.4, but the same result. Also tried without the c++11 flag, does not help either. Taking out the catch all clause gives me this:
terminate called after throwing an instance of 'std::ios_base::failure[abi:cxx11]*'
So what am I missing, and what can I do to fix this? The abi:cxx11 is also shown when I am NOT using the c++11 flag.
Aucun commentaire:
Enregistrer un commentaire