Why doesn't "new" throw an exception?

bridged with qdn.public.qnxrtp.devtools
Post Reply
John Nagle

Why doesn't "new" throw an exception?

Post by John Nagle » Sat Dec 21, 2002 4:47 am

Why doesn't "new" throw an exception on an out
of memory condition? I'm getting a signal instead,
even when I have a C++ exception handler for "...".

Using QNX 6.20 NC, gcc and lib as packaged with QNX.

John Nagle
Animats

Chris McKillop

Re: Why doesn't "new" throw an exception?

Post by Chris McKillop » Sat Dec 21, 2002 6:27 am

Are you enabling exceptions? By default gcc won't be using them. I am
also not 100% sure how good the libstdc++ is with exceptions. If you move
to QCC and the Dinkum C++ libs you will get exceptions on by default.

chris



John Nagle <nagle@downside.com> wrote:
Why doesn't "new" throw an exception on an out
of memory condition? I'm getting a signal instead,
even when I have a C++ exception handler for "...".

Using QNX 6.20 NC, gcc and lib as packaged with QNX.

John Nagle
Animats
--
Chris McKillop <cdm@qnx.com> "The faster I go, the behinder I get."
Software Engineer, QSSL -- Lewis Carroll --
http://qnx.wox.org/

John Nagle

Re: Why doesn't "new" throw an exception?

Post by John Nagle » Sat Dec 21, 2002 8:38 pm

Chris McKillop wrote:
Are you enabling exceptions? By default gcc won't be using them.
That's it. GCC somehow defaults to exceptions off.
I needed the "-fexceptions" flag on GCC.

Now I get a "throw" on an out of memory condition. Thanks.

This shouldn't have happened, though.
The "gcc" manual for gcc 2.95.3 (the one that comes
with QNX) indicates that this shouldn't have been necessary.
Note "It is enabled by default for languages like C++".

(Ref: http://gcc.gnu.org/onlinedocs/gcc-2.95. ... .html#SEC7)

-fexceptions
Enable exception handling. Generates extra code needed to propagate
exceptions. For some targets, this implies generation of frame unwind
information for all functions. This can produce significant data size
overhead, although it does not affect execution. If you do not specify
this option, it is enabled by default for languages like C++ which
normally require exception handling, and disabled for languages like C
that do not normally require it. However, when compiling C code that
needs to interoperate properly with exception handlers written in C++,
you may need to enable this option. You may also wish to disable this
option is you are compiling older C++ programs that don't use exception
handling.

I'm compiling a ".cpp" file, so the compiler should have had
exceptions on by default. Is GCC built to do something different
under QNX?

Exceptions defaulted to "off" in earlier versions of gcc, around
2.7, I think, but they're supposed to be on by default now.

John Nagle
Animats

John Nagle <nagle@downside.com> wrote:

Why doesn't "new" throw an exception on an out
of memory condition? I'm getting a signal instead,
even when I have a C++ exception handler for "...".

Using QNX 6.20 NC, gcc and lib as packaged with QNX.

John Nagle
Animats

Post Reply

Return to “qdn.public.qnxrtp.devtools”