At 10:14 AM +0200 10/18/02, Thomas Damme wrote:
>Hello,
>
>I found out, that the operator new just fails and quits the program without any 
>comment if there is not enough space to create an (C++) object.
>Can you give me some suggestions how to solve this?
>I dont want to wrap every new[] into ErrTry..ErrCatch in my code. A single function 
>that returns the object or NULL would be nice.
>Is there some kind wrapper-function to create an object via MemPtrNew() ?
>(Anyway, if you think Exceptions are the ultimate way, write me.)

[ General C++ advice, not really Palm-specific ]

new will throw a bad_alloc exception if it is unable to allocate the space.
This is what you are seeing. I suspect that ErrTry & ErrCatch will NOT catch this
behavior, since these are native C++ exceptions, not PalmOS exceptions.

However, there is a 'nothrow' variant of new, which will return NULL instead
of throwing.

Instead of writing:             pFoo = new Foo;
you write:              pFoo = new (nothrow) Foo;
(yeah, I know it looks strange).

hth,,
-- 
-- Marshall

Marshall Clow     Idio Software   <mailto:marshall@;idio.com>
Hey! Who messed with my anti-paranoia shot?

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to