Trapping "the index was outside the bounds of the array" error

I use Prop:LastChanceHook to hook the exception so before the user ever sees the Exception Message I can call ExInfo.LogException() to write the Exception Log file. That way I do not reply on the user to click “Log Info”. I also show a message more suited to End Users.

I attached small test project that displays this window to allow with Last Chance hooked and an option to use PROP:FatalErrorHook and cause an Index error:

Checking CHECK('Hook PROP:FatalErrorHook') my code gets the call and shows a simple message. The RTL passes no call stack and not much of details needed.

One idea was to have that Fatal message GPF with a Peek(0) which will throw an Exception so I get a call stack like below:

image

This adds FatalErrorTaker() to the call stack, but at least the original problem shows that was at line 88.

I don’t like using PEEK(0) as it shows the very common “Access Violation”. I took a quick try at causing an exception named “Array Bounds Exceeded”, but the below code just hung for a while then closed the program.

Does anyone know how to cause a specific exception?

RaiseException(UNSIGNED dwExceptionCode, UNSIGNED dwExceptionFlags, UNSIGNED nNumberOfArguments, LONG Address_lpArguments ),RAW,PASCAL,DLL(1)        
EXCEPTION_ARRAY_BOUNDS_EXCEEDED  EQUATE(0C000008Ch)
EXCEPTION_NONCONTINUABLE         EQUATE(1)          !Noncontinuable exception

   RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, EXCEPTION_NONCONTINUABLE, 0,0)

LogExceptionAndFatalError_20230606.ZIP (6.6 KB)

3 Likes