From: cascade AT swipnet DOT se Newsgroups: comp.os.msdos.djgpp Subject: Re: new throwing exception Date: Sat, 25 Dec 1999 16:25:25 GMT Organization: Deja.com - Before you buy. Lines: 34 Message-ID: <842qvj$sv$1@nnrp1.deja.com> References: <8414d9$32$1 AT nnrp1 DOT deja DOT com> NNTP-Posting-Host: 62.20.134.113 X-Article-Creation-Date: Sat Dec 25 16:25:25 1999 GMT X-Http-User-Agent: Mozilla/4.61 [en] (Win98; I) X-Http-Proxy: 1.0 x27.deja.com:80 (Squid/1.1.22) for client 62.20.134.113 X-MyDeja-Info: XMYDJUIDsouldoubt To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > new seems to throw an exception when there's some trouble allocating > memory (correct me if I'm wrong), but I can't understand how to catch > this exception. > > Mattias I've managed to figure out that new throws an exception called bad_alloc which is defined in , but if I write a program like this: #include #include void main(void) { char* foo; try { foo = new char[1000000000]; foo[999999999] = 'a'; } catch (bad_alloc e) { cout << "Gotcha!" << endl; } } I get a printout that says "Virtual memory exceeded in 'new'". Please, can anyone help? Mattias Sent via Deja.com http://www.deja.com/ Before you buy.