Exceptions are not being caught in a case where I expect them to be caught. The code is in 1 function in 1 cpp file which is compiled into a static library by GCC 4.2 and then linked into a Cocoa application. The code in question is
class runtime_error : public exception{
// More code
};
int foo( void ){
try {
if( x == 0 ){
throw std::runtime_error( "x is 0" );
}
}
catch( std::exception & e ){
// I expect the exception to be caught here
}
catch( ... ){
// But the exception is caught here
}
}
I can modify the code to be
int foo( void ){
try {
if( x == 0 ){
throw std::runtime_error( "x is 0" );
}
}
catch( std::runtime_error & e ){
// exception is now caught here
}
catch( … ){
}
}
The second version of the code only solves the problem for runtime_error exceptions and not other exception classes that might be derived from std::exception. Any idea what is wrong? Note the first version of the code works fine with Visual Studio.
Thanks,
Barrie