Exception Specifications
I'm a bit unsure about exception specifications and the rules that
they enforce.
I've had a look at the C++ spec and it doesn't state about the errors
that it enforces, if an exception is thrown in a function that isn't
specified in its exception specification (assuming there's one
there).
If I compile the code below on Solaris, Linux and AIX, I get the
program coring, causing the "std::exception" to be thrown back to the
runtime and the "catch (std::exception)" is not handled.
However if I run this on Windows (VC++6 and VC++8), the "catch
(std::exception") handler is used.
I know this is going a bit platform specific, but I'm just wondering
what the proper behaviour for C++ should be?
I would expect the Unix platforms to have the correct behaviour as we
are invalidating the exception specifier so that should *not* be
allowed.
=========================================
#include <iostream>
#include <exception>
class sys_exception { };
void f ( ) throw (sys_exception)
{
throw std::exception( );
}
int main ( )
{
try
{
f( );
}
catch (sys_exception& se)
{
std::cerr << "System Exception thrown" << std::endl;
}
catch (std::exception& e)
{
std::cerr << "Exception thrown" << std::endl;
}
catch (...)
{
std::cerr << "Unknown Exception thrown" << std::endl;
}
return 0;
}
===================================
Cheers,
- Keith