By default, in Pascal, error handling is provided by the compiler. For this reason, the program ends by displaying a message starting with Runtime error followed by error numbe
So if the programmer wants to handle the errors itself it must disable the option for error checking by the compiler, using the Option menu and the Build ... or to use the compiler directives directly in the code source program.
For example, if in a given program, we want to open a file by the reset and that the file does not exist, an error message is displayed and the program is stopped.
To avoid this, we can test whether or not a file and then act accordingly by using the compiler directive $ I and IOresult as the function that wil return the result of entry / exit. With the directive ($ I-), the programmer must manage itself this type of error.
This is a program that lets you enter the physical name of a file and open it. If the file does not exist it is created without ending the program on the error: runtime error 2 at ... (no file).
f : File;
name : string;
Write ('File Name: '); Readln (name);
Assign (f, nom);
If IOresult <> 0 then Rewrite (f);
Thanks to Zouari Lazhar for this tip.
This document, titled « Error Management under Pascal », is available under the Creative Commons
license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM