U
Urs Thuermann
In Stroustrup's "The C++ programming language" I read that throwing an
exception that is not declared to be expected in a function causes
std::unexpected() to be called. I tried the difference with the following code
#include <iostream>
#ifdef NO_EXCPT
int foo() throw()
#else
int foo() throw(int)
#endif
{
throw 1;
}
int main()
{
try {
foo();
} catch (...) {
std::cerr << "Exception caught\n";
}
}
But my question is, is there any good reason to intentionally throw
unexpected exceptions? If not, shouldn't the compiler warn about code
that clearly does so, i.e. the above code with NO_EXCPT defined?
urs
exception that is not declared to be expected in a function causes
std::unexpected() to be called. I tried the difference with the following code
#include <iostream>
#ifdef NO_EXCPT
int foo() throw()
#else
int foo() throw(int)
#endif
{
throw 1;
}
int main()
{
try {
foo();
} catch (...) {
std::cerr << "Exception caught\n";
}
}
But my question is, is there any good reason to intentionally throw
unexpected exceptions? If not, shouldn't the compiler warn about code
that clearly does so, i.e. the above code with NO_EXCPT defined?
urs