Intentionally crash your program

When developing the Watson error reporting features (see Dr. Watson: Please send in your error report, and What is a C0000005 crash?, What was Dr. Watson's original name?)) it was useful to cause a crash intentionally

In VFP we have a simple way to crash intentionally.

Try executing this: SYS(1079)

A MessageBox comes up saying “Cause an intentional crash for test purposes” with an OK and Cancel button. If you cancel, nothing happens. If you choose OK, then code like this gets executed:

char *cp=0; // declare a pointer to a char initialized to point to 0

*cp = 0; // Put a value of 0 into address 0

which causes an Access Violation Exception, simulating an error occurring in an application.

This will typically cause a Dr. Watson dialog to appear.

If you execute SYS(1079) in your application code somewhere (or somehow cause an exception), then the VFP call stack also gets added into an error log and shown in a MessageBox.

foo(5)

PROCEDURE foo(n)

          IF n = 1

                   SYS(1079)

          ELSE

                   foo(n-1)

          ENDIF

RETURN

Fatal error: Exception code=C0000005 @ 11/16/05 04:14:29 PM. Error log file: D:\Fox90\VFP9err.log

            Called from - foo line 46 {d:\fox90\test\tt.prg d:\fox90\test\tt.fxp}

            Called from - foo line 48 {d:\fox90\test\tt.prg d:\fox90\test\tt.fxp}

            Called from - foo line 48 {d:\fox90\test\tt.prg d:\fox90\test\tt.fxp}

            Called from - foo line 48 {d:\fox90\test\tt.prg d:\fox90\test\tt.fxp}

            Called from - foo line 48 {d:\fox90\test\tt.prg d:\fox90\test\tt.fxp}

            Called from - tt line 43 {d:\fox90\test\tt.prg d:\fox90\test\tt.fxp}

I believe this VFP call stack dump is very useful for developers to identify the actual line of VFP code that caused the crash, allowing the user to possibly come up with a workaround. Has this call stack dump been useful to anybody?