I've made a simple function that takes a vector as an argument. If the vector is empty, it throws a domain_error (I've included stdexcept).
I'm feeding it an empty vector from the main loop just to learn try...catch statements and when it catches the error, it's supposed to print something and carry on. Instead, however, it hangs on catching the error. I know I'm close, though, because if I use the step-through debugger in code::blocks and tell it to go to the next line, it continues as I'd expect it to. Why won't the executable do this on its own?
Sorry if this has been asked before, my search didn't come up with anything, and thanks in advance.
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stdexcept>
#include <cstdlib>
using namespace std;
double get_median(vector<double> vec)
{
if (vec.size() == 0)
throw domain_error("Can't find median of empty vector");
return 5.5;
}
int main()
{
vector<double> vec;
try
{
double med = get_median(vec);
}
catch (domain_error& e)
{
cout << "exception handled" << endl;
}
system("pause");
return 0;
}