From: "Paul Derbyshire" 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 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit 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 Precedence: bulk >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|