Besides the normal program termination events triggered by concluding the program and arriving at the END or by a RETURN from the program module body, it is possible to terminate programs in other ways. This section discusses one of those ways, and also presents some strategies for action after a termination event has taken place.
Some programmers may feel it necessary to kill a program that has encountered serious difficulties of some kind. Modula-2 provides the HALT command for such cases. It is similar to a simple RETURN, except that HALT:
For instance, when the following Module was run, the memory allocated to the boolean flag happened to be interpreted as TRUE, and the program halted.
MODULE HaltDemo1; VAR reallyAwfulCondition : BOOLEAN; BEGIN (* some code *) IF reallyAwfulCondition THEN HALT END; (* some more code *) END HaltDemo1.
In one specific version used, a debugging environment was entered, part of the display for which is shown in figure 10.8.
Of course, the precise behaviour after the HALT is called is implementation defined, and some implementations will report nothing at all. In such implementations, a separate non-standard command such as BREAK (perhaps in a compiler directive) may be employed to invoke the debugging environment. There is a language difference between HALT and a normal termination, however, and this will be detailed as part of the next section.