A student of mine submitted some C++ code similar to the following one. The code compiles and runs, but the throw
statement produces the following message:
terminate called after throwing an instance of 'int'
If I make the function void
the compiler complains
invalid use of ‘void’
on the line that contains the throw
statement (expectedly).
class TestClass
{
public:
int MyException()
{
return 0;
}
void testFunc()
{
throw MyException();
}
};
int main(int argc, char** argv)
{
TestClass tc;
tc.testFunc();
return 0;
}
So, how does C++ interpret MyException
since the code is "correct" ?