From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: Minor problem with operator new[] Date: Tue, 03 Dec 1996 20:01:14 -0800 Organization: Alcyone Systems Lines: 30 Message-ID: <32A4F78A.494BAE74@alcyone.com> References: <5800sc$5jp AT ns2 DOT southeast DOT net> NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp M. Edward Kiser wrote: > Recently, just out of curiosity, I decided to see how much memory I > could allocate under various conditions. I wrote this program to find > out, based on the assumption that operator new[] would throw an > exception if it couldn't allocate the memory. But it doesn't throw the > exception. It prints a message > > "Virtual memory exceeded in new" > > and terminates the program. This is very un-ANSI-like! As far as I can tell, this is not _quite_ draft standard C++ behavior (note there is no ANSI C++ standard as of yet), but is acceptable. Get a good book on C++ and look up set_new_handler. Basically, the default behavior of operator new should be to return the null pointer when unable to allocate memory. However, and this is usually the case, a new_handler is created (via set_new_handler) to automatically terminate the program. (Most implementations do this -- I'm not sure if they are strictly draft standard conforming.) Bottom line, though, is that operator new does _not_ throw an exception on failure. (Certainly as far as I can see in my reference books here.) -- Erik Max Francis | max AT alcyone DOT com Alcyone Systems | http://www.alcyone.com/max/ San Jose, California | 37 20 07 N 121 53 38 W &tSftDotIotE | R^4: the 4th R is respect "But since when can wounded eyes see | If we weren't who we were"