Whenever I input anything other than an integer, I was hoping for the catch block to execute but instead I get this error:
Unhandled exception at 0x002D0C39 in A03.exe: Stack cookie instrumentation code detected a stack-based buffer overrun. occurred
which takes me to:
if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE)) {
__fastfail(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE);
}
I've tried varieties of catch blocks and exceptions with the same error. Can someone tell me what I'm doing wrong? Thank you!
Here is the code:
int main() {
while (true) {
std::string input;
int num = 0;
std::cout << "What number do you want to show?";
std::cin >> input;
try
{
num = std::stoi(input);
if (num >= 0 && num < 10)
{
std::cout << "FILLER: This will draw the number";
exit(0);
}
else {
std::cout << "FILLER: This is the else";
exit(1);
}
}
catch (std::runtime_error e)
{
std::cout << e.what();
//std::cout << "That is not a valid number." << '\n';
}
}
return 0;
}
Please login or Register to submit your answer