Add an exception about bad_alloc in a vector of vectors

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.
Last edited on
I have a problem about adding a try,catch if the matrix is too big to be stored in memory.

What exactly is the problem?

I tried to insert try,catch in different part of the program but noone worked.

Why didn't it work?

If you got error messages, post the code that generates the messages along with the complete error messages.

ps:i don't know why javascript::tx doesn't function

Because this site uses bb codes. Highlight the code and press the <> icon to the right of the editor window.
i edit
Last edited on
Did you include the <exception> include file?

Perhaps the problem is elsewhere.

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.
Topic archived. No new replies allowed.