The getlasterror function returns the number of the last trappable error that occured. The type of the value returned by this function is always integer.
When error trapping is enabled your program automatically checks for trappable errors after each operation that could cause a trappable error. Your program will terminate if a trappable error occurs. If you do not want this default behavior you can disable error trapping using the built-in procedure traperrors and call the getlasterror function to determine if any errors occurred.
After this function is called the error number is cleared to zero (this prevents the function from returning the same error more than once). However because of this, if you need to refer to the error number more than once you should store the result of the first call in a variable.
New programs should use getlasterror instead of ioresult, which dispite its name also returns all trappable errors not just I/O errors. ioresult continues to be supported for compatibility reasons only.
For example the following is incorrect:
if getlasterror <> 0 then case getlasterror of 1: writeln('Error erasing file'); 2: writeln('Error renaming file'); 3: writeln('File is undefined') end
since the second call to getlasterror will always return 0. Instead you should do something like this:
errnum := getlasterror; if errnum <> 0 then case errnum of 1: writeln('Error erasing file'); 2: writeln('Error renaming file'); 3: writeln('File is undefined') end
Operating Systems: All Standard Pascal: No