Difference between revisions of "runtime error"
(review) |
|||
Line 17: | Line 17: | ||
Run-time errors are the classical imperative approach in order to avoid inconsistent program states, which may eventually cause faulty program behavior. | Run-time errors are the classical imperative approach in order to avoid inconsistent program states, which may eventually cause faulty program behavior. | ||
If FPC's {{Doc|package=RTL|unit=sysutils|text=<syntaxhighlight lang="pascal" enclose="none">sysUtils</syntaxhighlight> unit}} is included, all run-time errors become [[Exceptions|exceptions]] (cf. {{Doc|package=RTL|unit=system|identifier=runtimeerrors|text=<syntaxhighlight lang="pascal" enclose="none">system.runTimeErrors</syntaxhighlight>}} for details). | If FPC's {{Doc|package=RTL|unit=sysutils|text=<syntaxhighlight lang="pascal" enclose="none">sysUtils</syntaxhighlight> unit}} is included, all run-time errors become [[Exceptions|exceptions]] (cf. {{Doc|package=RTL|unit=system|identifier=runtimeerrors|text=<syntaxhighlight lang="pascal" enclose="none">system.runTimeErrors</syntaxhighlight>}} for details). | ||
− | Unlike run-time errors those can be caught by <syntaxhighlight lang=" | + | Unlike run-time errors those can be caught by [[Try|<syntaxhighlight lang="pascal" enclose="none">try</syntaxhighlight>]]...[[Except| <syntaxhighlight lang="pascal" enclose="none">except</syntaxhighlight>]] |
+ | [[On|<syntaxhighlight lang="pascal" enclose="none">on</syntaxhighlight>]]...[[Do|<syntaxhighlight lang="pascal" enclose="none">do</syntaxhighlight>]] ... [[End|<syntaxhighlight lang="pascal" enclose="none">end</syntaxhighlight>]] [[Block|blocks]], provided a mode allowing exceptions – such as [[Mode ObjFPC|<syntaxhighlight lang="pascal" enclose="none">{$mode ObjFPC}</syntaxhighlight>]] or [[Mode Delphi|<syntaxhighlight lang="pascal" enclose="none">{$mode Delphi}</syntaxhighlight>]] – is being used. | ||
A run-time error causes the program to terminate, while an exception may give the opportunity to “fix” the problem. | A run-time error causes the program to terminate, while an exception may give the opportunity to “fix” the problem. | ||
This standard behavior of {{Doc|package=RTL|unit=system|identifier=runerror|text=<syntaxhighlight lang="pascal" enclose="none">system.runError</syntaxhighlight>}} can be altered by assigning a non-[[Nil|<syntaxhighlight lang="pascal" enclose="none">nil</syntaxhighlight>]] value to {{Doc|package=RTL|unit=system|identifier=errorproc|text=<syntaxhighlight lang="pascal" enclose="none">system.errorProc</syntaxhighlight>}}. | This standard behavior of {{Doc|package=RTL|unit=system|identifier=runerror|text=<syntaxhighlight lang="pascal" enclose="none">system.runError</syntaxhighlight>}} can be altered by assigning a non-[[Nil|<syntaxhighlight lang="pascal" enclose="none">nil</syntaxhighlight>]] value to {{Doc|package=RTL|unit=system|identifier=errorproc|text=<syntaxhighlight lang="pascal" enclose="none">system.errorProc</syntaxhighlight>}}. |
Revision as of 07:46, 14 April 2019
│
English (en) │
suomi (fi) │
A run-time error is an irreparable error condition that arises during the run-time, i.e. the execution of a program.
behavior
The FPC inserts code to detect a vast number of error situations. If such a situation is encountered, the standard run-time library will initiate the termination of the program. A run-time error number, and the address the error occurred at is being printed. This is the safest and cheapest error treatment.
comparative remarks
compile-time errors
In contrast to compile-time errors, which the compiler detects during compilation, run-time errors depend on the state of the program, thus can not be foreseen in advance. If a compile-time error is encountered, no executable program is generated.
exceptions
Run-time errors are the classical imperative approach in order to avoid inconsistent program states, which may eventually cause faulty program behavior.
If FPC's sysUtils
unit is included, all run-time errors become exceptions (cf. system.runTimeErrors
for details).
Unlike run-time errors those can be caught by try
... except
on
...do
... end
blocks, provided a mode allowing exceptions – such as {$mode ObjFPC}
or {$mode Delphi}
– is being used.
A run-time error causes the program to terminate, while an exception may give the opportunity to “fix” the problem.
This standard behavior of system.runError
can be altered by assigning a non-nil
value to system.errorProc
.