Re: Unhandled Exception - can I get more information?
On Thu, 9 Aug 2007 10:48:00 -0700, Alan Williams-Key
<AlanWilliamsKey@discussions.microsoft.com> wrote:
I have an array of objects o_array.
int j;
CObject* ob = &o_array[j]; // without initialising j
ob->some_field = some_value; // usually causes exception
I tried to catch this as you suggested but it still doesn't.
You're making four wrong assumptions:
1. Array accesses are checked. They are not.
2. The value of j is out-of-bounds for the array. Uninitialized local
variables have indeterminate initial values. It may or may not be illegal.
3. If j is an illegal index, it is sufficiently illegal to cause an address
exception. By that I mean it results in trying to access memory you don't
have access to; perhaps it's read-only, or it's not "committed". (See the
VirtualAlloc documentation for an explanation.)
4. If an address exception is thrown, it is catchable as a CException*,
which I guess is what you tried. It's actually a Windows structured
exception, which is a very different creature.
To deal with access violations (that actually occur <g>), see
__try/__except, but realize you're using it as a debugging aid. It's no
good to swallow random access violations and proceed as if your program is
working correctly, because it may well have corrupted user data; after all,
the access violation is due to a bug, and who knows what state your program
is in then? Not only that, indiscriminate interception of structured
exceptions can interfere with the normal operation of the system in certain
contexts.
--
Doug Harrison
Visual C++ MVP