At 7:49 AM -0600 12/15/02, Jeff Wheeler wrote:
>CodeWarrior 8
>Palm OS 5 SDK
>
>I'm working on an app that is written largely in C.  I use MemPtrNew() and
>MemHandleNew() and religiously check the return value.
>
>The project uses some shared code, from another developer, that is written
>in C++.  So, in the project settings, I have turned on the C++ compiler
>option.
>
>The shared code contains stuff like this:
>
>    Char * p = new Char[512];
>    if (p == NULL)
>        {
>        return;
>        }
>
>In "Targeting the Palm OS Platform", I read on page 89: "Both new and delete
>throw exceptions that require global variables."  This makes me suspect that
>as soon as new and delete are used, I need to also use exception handling.
>However, I haven't been successful at finding other docs that discuss
>exception handling, so I have a few simple questions.  Thanks in advance for
>any assistance you can provide.
>
>1. If the "new" allocation above fails, an exception is thrown and the "if
>(p == NULL)" statement is never executed.  Is this correct?

Yes.

>2. In the project settings, I have NOT yet selected "enable C++ exceptions".
>Does this prevent "new" from throwing an exception, or merely prevent me
>from catching it? 

Don't know - probably the latter, since the exception is thrown from
the library function "new".

>2a. Is there a way to make "new" simply return NULL on failure rather than
>throw an exception?

Yes.
Change the line to

        Char * p = new (nothrow) Char[512];

>3. Threads in the archive suggest that CodeWarrior C++ exceptions will do
>stack unwinding.  Is this correct?

Yes.

>4. If new throws an exception and it is never caught, what happens?  Does
>the app simply exit back to the launcher?

In C++ parlance, an uncaught exception will cause terminate () to be called.
I don't know what that does on PalmOS - certainly it will cause the app to quit.
Back to the launcher is as good a guess as anyones.

>5. What is the proper syntax for catching the exception?
>
>    try
>        {
>        SomeFuncThatMayCallNew();
>        }
>    catch
>        {
>        // handle error condition here
>        }

Almost:
        catch ( <exception type> ) {

>6. Any recommended reading?

Stroustrop's book (get the third edition ).
-- 
-- Marshall

Marshall Clow     Idio Software   <mailto:[EMAIL PROTECTED]>
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