How to write EXE programs with Error Handling


1. How do I modify my programs to handle errors?

All run-time errors in a program are handled by the ErrorHandler function which by default displays a message and halts. To see why an error occurs, recompile the program with full debug information (/D2) and re-run it. You can do this by clicking the debug icon on the Developer Environment toolbar:

EXE Programs with Error Handling - running in debugger

When the error occurs the debug window pops up which shows where the program has crashed. You can step through code and examine variables, get help on the error, and track down the problem. When you have identified the problem, stop the debugger, change the code and re-run the program.

Sometimes programs have errors but do not crash - typically this is caused by wrong calculations or logic errors. To fix these use the automated program checks, such as preconditions, postconditions and assertions. These are useful as they show you as soon as anything has gone wrong, since the precondition / postcondition / assertion failure causes a run time error which you can then debug.

Or you can run the program in the Developer Environment and use the debugger to step through code to see what is happening.

When releasing a program you can make it more error proof by modifying ErrorHandler to optionally display an error and continue running.

2. Is exception handling supported?

Yes. Refer to the topic above.

3. How do I check for memory leaks in a program?

You don't have to, because all memory management is handled automatically. A program will not leak memory, unless there is an undiscovered bug in the compiler.