I wrote some code that encounters an exception if the given user input is invalid so I put it in a try/catch block yet it still threw an exception. The code itself is quite long so here's a simplified version of the code that also encounters the exception. The exception itself is clear, the position "3" doesn't exist so naturally it would throw an exception, but it's inside of a try/catch block so it should get caught, but it doesn't.
int main() {
try
{
vector<string> test = vector<string>{ "a","b","c" };
string value = test[3];
}
catch (...)
{
}
}
Running this code just results in the following exception regardless of whether or not it's in a try/catch block.
I also tried specifying the exception (const out_of_range&e
) but that didn't help either. It just caused the exact same exception.
int main() {
try
{
vector<string> test = vector<string>{ "a","b","c" };
string value = test[3];
}
catch (const out_of_range&e)
{
}
}
I'm using Visual Studio, could this be an issue with the IDE or the compiler it uses?