With this code:
int main()
{
try
{
throw -1;
}
catch (int& x)
{
std::cerr << "We caught an int exception with value: " << x << std::endl;
}
std::cout << "Continuing on our merry way." << std::endl;
return 0;
}
We have:
/tmp$ ./prorgam.out
Continuing on our merry way
We caught an int exception with value: -1
How does the catch
block read -1
as int&
? We couldn't assign a value to a non-const lvalue reference.
And why is the second std::cout
statement executed before the first std::cerr
statement?