I am trying to learn exception throwing on C++ My code is basically:
int nums[3] = { 1, 5, 57 };
try {
cout << nums[4] << endl;
}
catch (logic_error e) {
cout << e.what() << endl;
}
I thought that here I would get an out_of_range exception and I could catch it, but the program runs normally, and I get this as a result:
-277035873
It's always a different negative number. Can somebody explain to me what's happening? I couldn't find an answer online to this specific case.
I am using Visual Studio 2017 Version 15.9.34
Thanks.