On 22/01/2015 10:41 AM, Charles Mills wrote:
Thanks. Yeah, that's it. Put in NEWEXCP and now I get my std::exception
routine called with "bad allocation."

Geez, IBM -- the Language Reference and the Library Reference are in
conflict with each other and both incomplete. Both should reference
LANGLVL(NEWEXCP).

Also #pragma operator_new which claims the default is throwsexception -- the
default actually is returnsnull.

Backwards compatibility is sacrosanct to IBM so I'm not surprised!

returnsull is the default in the doco I read.

Only a couple of hours wasted debugging a S0C4.

Been there and felt the pain. IBM should at least change the doc to warn C++ programmers that using the STL without NEWEXP is a drift into sharky waters.


Charles

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On
Behalf Of David Crayford
Sent: Wednesday, January 21, 2015 5:42 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: What am I missing about C++ new[] failure?

I got burned by the same problem years ago. z/OS C++ does not throw
bad_alloc() by default for compatibility reasons (brain damaged).
To turn it on specify the compiler option LANGLVL(NEWEXCP).

On 22/01/2015 9:29 AM, Charles Mills wrote:
I have a C++ program in which I am trying to allocate an
unreasonably-large character array with new[]. I know it's
unreasonably large - I'm a developer testing something. It's 6.3MB --
not ridiculous, but in excess of the memory available (apparently).

It appears to me that new is simply returning a NULL pointer, with no
error indication. That seems inconsistent with the C++ manual which
says "If you do not specify your own set_new_handler() function, new
throws an exception of type std::bad_alloc." I have an exception
handler that is known to work generally and it is not getting called. I do
not call set_new_handler().
Am I missing something? Do others know that new generally fails as
documented?
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to