The following code does VERY strange things in the debugger. Is there
anything wrong with the following code, UB or anything else?
#include <iostream>
#include <exception>
#include <stdexcept>
int main()
{
int * parser;
try
{
parser = 0;
}
catch (std::out_of_range & err)
{
}
catch (std::bad_alloc & err)
{
return 0; // debugger jumps to here after hitting final brace -
"runs" this statement as many times as there are returns in catches.
}
catch (std::domain_error & err)
{
return -1;
}
catch (std::exception & err)
{
std::cerr << err.what() << std::endl;
}
catch(...)
{
return -1;
} // debugger jumps to here after running code in try..
return 0; // debugger finally jumps to here and leaves...other code in
this area will run but has been removed for brevity.
}
Granted, it isn't a normal thing to do, but AFAICT the standard
explicitly allows it.