Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 105901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:30:44+00:00 2026-05-11T01:30:44+00:00

I just started reading Effective C++ today and got to the point where the

  • 0

I just started reading Effective C++ today and got to the point where the author talks about the operator new.

The book explains very well how you can catch (with various degrees of elegance) the std::bad_alloc exception that the operator new can raise if you run out of memory.

My question is: How often do you check for the case when there isn’t enough memory to instantiate a object, if at all? and why? Is it worth the hassle?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:30:44+00:00Added an answer on May 11, 2026 at 1:30 am

    I catch exceptions when I can answer this question:

    What will you do with the exception once you’ve caught it?

    Most of the time, my answer is, ‘I have no idea. Maybe my caller knows.’ So I don’t catch the exception. Let it bubble up to someone who knows better.

    When you catch an exception and let your function proceed running, you’ve said to your program, ‘Never mind. Everything’s fine here.’ When you say that, by golly, everything had better be fine. So, if you’ve run out of memory, then after you’ve handled std::bad_alloc, you should not be out of memory anymore. You shouldn’t just return an error code from your function, because then the caller has to check explicitly for that error code, and you’re still out of memory. Your handling of that exception should free some memory. Empty some caches, commit some things to disk, etc. But how many of the functions in your program do you really want to be responsible for reducing your program’s memory usage?

    If you cannot solve the problem that triggered the exception, then do not handle the exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to WCF service, matter a fact I just started reading
I am very new to cuda and started reading about parallel programming and cuda
I just started reading on Douglas Crockford's Javascript The Good parts where he explains
I have just started reading about ORMLite since I am interested in using it
I just started programming in C# and was reading about dividing your application /
I just started learning ASP.NET MVC4 today. After reading tutorials, downloading VS 2012, and
I just started reading about JPA and its implementation in Hibernate. To understand the
I've just started reading C and have a question about a macro. How can
I am just learning about escaping things and started reading about how it could
I have just started reading a Hibernate book and it says go to Hibenrate.org

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.