Catch bad_alloc?

K

kk_oop

I'm looking for opinions for or against catching std::bad_alloc when I
use the "new" operator. I searched through this newsgroup and the
Internet, and I don't see clear opinions either way. Note that I am
using gc++ version 3.2 on a unix platform, so I'm not concerned with
any points unique to VC++.

Thanks!

Ken
 
B

Ben Pope

I'm looking for opinions for or against catching std::bad_alloc when I
use the "new" operator. I searched through this newsgroup and the
Internet, and I don't see clear opinions either way. Note that I am
using gc++ version 3.2 on a unix platform, so I'm not concerned with
any points unique to VC++.

Depends if you want to handle memory errors. Generally it's a good
idea, but often you can't do very much but close the program. It's
always nice to tell the user that they've run out of memory before
crashing hard :).

It's possible you can dump some other data, to free up memory and
continue. It's your call.

Ben Pope
 
M

Markus Moll

Hi

Ben said:
It's possible you can dump some other data, to free up memory and
continue. It's your call.

This is better done in a new_handler, imho.

Markus
 
B

Bo Persson

Markus Moll said:
Hi



This is better done in a new_handler, imho.

That's good at the global level. In a layered application, it might be
better to have a separate catch statement at some of the intermediate
levels.


Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,816
Messages
2,569,713
Members
45,500
Latest member
João Cardoso

Latest Threads

Top