>If there is a way to catch various errors before they pop up dialogs, then
>it should be reasonably trivial to wrap these in a mechanism to translate
>into C++ exceptions. Now, the question is: Is there a way to intercept
>these errors before the system kicks into default behaviors?
You could patch SysFatalAlert, but on release ROMs this only gets
called when things are so messed up that you probably wouldn't be
able to do much in your handler before dying a horrible death.
>You should be able to combine the system's ErrTry/ErrCatch/ErrEndCatch with
>C++ exception handling.
I think this would be a bit dangerous, similar to mixing
setjmp/longjmp calls with C++ try/catch/throws. If you threw an error
using the Palm OS mechanism, it wouldn't trigger proper C++ cleanup,
and if you threw a C++ exception, then the Palm OS exception stack
could get messed up. My advice is to use one or the other, not both.
>You'll just have to be aware that the C++ exception
>handlers won't catch the system errors, and vice versa. However, this only
>works if the system routine that originally sees the error uses the ErrThrow
>system call. A quick scan through the PalmOS source code indicates that
>ErrThrow is almost never used (but I can't really reveal more than that, due
>to the Palm NDA).
Errors encountered by Palm OS are either returned via a result code,
or they trigger a fatal alert - no exceptions are thrown. On debug
ROMs you'll get fatal alerts for a variety of problems, some of which
get returned as non-zero results on release ROMs.
>Conclusion: use either mechanism, and be consistent. The system error
>trapping calls won't trap real crash-worthy errors. If you're doing C code,
>ErrTry et al looks pretty promising. If you're doing C++, use the
>compiler's exception handling so the language will handle
>constructors/destructors correctly.
The biggest problem currently with C++ exceptions is that they rely
on being able to access global variables, so you can't use them in
any code that can get called as a result of a sub-launch. An
interesting tweak would be to modify the Metrowerks exception code to
use the Palm OS try/catch chain (which is available during a
sub-launch) as a way around this limitation.
-- Ken
Ken Krugler
TransPac Software, Inc.
<http://www.transpac.com>
+1 530-470-9200
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/