delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/26/16:16:42

From: Carsten Rohde <crohde AT wtal DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem with "new"
Date: Wed, 26 Aug 1998 21:56:02 +0200
Organization: Customer of SpaceNet GmbH
Lines: 41
Message-ID: <35E46852.C03FE770@wtal.de>
References: <35e404cf DOT 33475 AT news DOT space DOT net>
NNTP-Posting-Host: line236.kdt.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi!

I had the same problem and tried a solution 
presented in my C++ book:

In C++ you should be able to catch an exception called 
bad_alloc: 

#include <iostream>
#include <new>

try
{
  *int test = new int[1000];	
}

catch(bad_alloc)
{
  cerr << "your_errormessage" << endl;
  exit(1);
}

If you want to check for the NULL pointer 
the (nothrow) argument is required :
	*int test = new(nothrow) int[1000];
	// ...

That's what my book sais :-) 

But this is not what I experienced with my v. 2.7.2.1.
"bad_alloc" and "nothrow" seem to be unknown.
What I(we) probably need is a possibility 
to either make the compiler behave like an old one 
( return a NULL pointer ) or enable it to catch the "bad_alloc".

Has anyone got similar problems or ( even better ) a solution ?

tia

Carsten

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019