I have this code here:
int main()
{
try // throw int
{
int a = 7;
double b = 9.9;
// throw int to show that only the double catch handler executes
throw a < b ? a : b;
} // end try
catch ( int x ) // catch ints
{
cerr << "The int value " << x << " was thrown\n";
} // end catch
catch ( double y ) // catch doubles
{
cerr << "The double value " << y << " was thrown\n";
} // end catch
} // end main
The output yields:
The double value 7 was thrown
I am trying to understand why the int (a=7) was caught by the double handler.
In other words, why wasn't the int handler executed, even though it comes before the double handler?
Could it be due to some implicit conversion? If so, I'm not quite sure how the conditionals (a and b) are involved.
Any help would be grateful. Thanks!