delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/13/09:46:54

From: "Paul Derbyshire" <pderbysh AT usa DOT net>
Newsgroups: comp.os.msdos.djgpp
References: <35594e81 DOT 4169631 AT 192 DOT 168 DOT 1 DOT 250>
Subject: Re: What does new do when memory is exhausted?
Lines: 35
Organization: The Chaos Zone
MIME-Version: 1.0
Message-ID: <8uh61.2667$z15.2572850@news21.bellglobal.com>
Date: Wed, 13 May 1998 13:45:40 GMT
NNTP-Posting-Host: 206.172.228.122
NNTP-Posting-Date: Wed, 13 May 1998 09:45:40 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>The ANSI C++ standard states that new should throw an exception when
>out of memory.

That it does.

>Is this the case with GCC 2.8.1? If so what exception is it?  Is it
>bad_alloc?

In GCC 2.8.1, for some unfathomable reason, it prints "Virtual memory exhausted
in new" and dies.
This can be fixed:

void my_new_handler (void) { throw bad_alloc(); }

int main (void) {
  set_new_handler (my_new_handler);  // See relevant C++ docs, e.g. Stroustrup.
  /* ... */
  try {
    int *foo=new int[len];
  } catch (bad_alloc) {
    /* ... */
  }
  /* ... */
}


--
   .*.  "Clouds are not spheres, mountains are not cones, coastlines are not
-()  <  circles, and bark is not smooth, nor does lightning travel in a
   `*'  straight line."    -------------------------------------------------
        -- B. Mandelbrot  |http://www3.sympatico.ca/bob.beland/indexn2f.html
_____________________ ____|________     Paul Derbyshire     pderbysh AT usa DOT net
Programmer & Humanist|ICQ: 10423848|


- Raw text -


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