|
From: | Ulrich Lauther |
Subject: | Re: How to test memory allocation with new ? |
Date: | Mon, 1 Nov 2004 16:24:49 +0000 (UTC) |
In gnu.g++.help Sharad Kala <no_spam.sharadk_ind@yahoo.com> wrote: : > I told you in my earlier reply too that new throws std::bad_alloc on : > exception. You need to wrap the new in a try-catch block (catching : > std::bad_alloc). : Something like - : try{ : char *pp = new char[n]; : //... : } : catch(std::bad_alloc) : { : cout << "New failed"; : } : Sharad or else: char* pp = new(nothrow) char[n]; if (! pp) { // new failed // do something } -- -lauther [nosave] ---------------------------------------------------------------------------- Ulrich Lauther ph: +49 89 636 48834 fx: ... 636 42284 Siemens CT SE 6 Internet: Ulrich.Lauther@siemens.com
[Prev in Thread] | Current Thread | [Next in Thread] |