I have a .csv file that i have to read and create a matrix through vector of vectors.
I have a problem about adding a try,catch if the matrix is too big to be stored in memory.
I tried to insert try,catch in different part of the program (before only the first push back,after before the while)but none worked.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
try {
stringstream convertor(line);
while (getline(convertor, token,','))
{
tmp.push_back(stoi(token));//first vector made by int read from csv file
}
matrix.push_back((tmp));
}
catch (std::exception& ba)
{
cerr << "bad_alloc caught: " << ba.what() << '\n';
}
If i give to the program, through .csv file, a big matrix that cannot be stored ( i receive a core dumped problem,so it's obvious that the program doesn't enter in the catch but i don't know why.
Have you run the program with your debugger to find out exactly where your program is crashing? The debugger should be able to tell you exactly where it detects the problem.