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

  • Home
  • SEARCH
  • 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 3635414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:54:04+00:00 2026-05-19T00:54:04+00:00

In a school project of mine, I was requested to create a program without

  • 0

In a school project of mine, I was requested to create a program without using STL

In the program, I use a lot of

Pointer* = new Something;
if (Pointer == NULL) throw AllocationError();

My questions are about allocation error:

  1. is there an automatic exception thrown by new when allocation fails?
  2. if so, how can I catch it if I’m not using STL (#include "exception.h")?
  3. is NULL testing enough?

Thank You.
I’m using eclipseCDT(C++) with MinGW on Windows 7.

  • 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. Editorial Team
    Editorial Team
    2026-05-19T00:54:04+00:00Added an answer on May 19, 2026 at 12:54 am

    Yes, the new operator will automatically thrown an exception if it cannot allocate the memory.

    Unless your compiler disables it somehow, the new operator will never return a NULL pointer.

    It throws a bad_alloc exception.

    Also there is a nothrow version of new that you can use:

    int *p = new(nothrow) int(3);
    

    This version returns a null pointer if the memory cannot be allocated. But also note that this does not guarantee a 100% nothrow, because the constructor of the object can still throw exceptions.

    Bit more of information: http://msdn.microsoft.com/en-us/library/stxdwfae(VS.71).aspx

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

Sidebar

Related Questions

For a school project I need to create a program and it'd be nice
For a school project, I need to create a way to create personnalized queries
I am trying to use Qt for a project in school but am running
For our school project, we are tasked to define a design document describing the
I'm working on a school project and I'm getting some weird errors from Xcode.
I'm working on a project for school, and I'm implementing a tool which can
For my school work, I do a lot of switching computers (from labs to
A school project has me writing a Date game in C++ (example at http://www.cut-the-knot.org/Curriculum/Games/Date.shtml
For a school project I'm making a simple Job Listing website in ASP.NET MVC
I'm in a school project on information security, and one of the assignments is

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.