Still wrongly documented as System.Exit
Function [WayBack], most people think it is a statement.
However, it is a compiler intrinsic procedure
in the System
unit that – when called inside a real function
– optionally accepts a parameter with the same type as the encompassing function because it is a compiler intrinsic. It kind of acts as an overloaded procedure, but in fact translate to machine code via an intermediate parse tree.
The parameterless version has been there since at least Turbo Pascal 3.0, but the parameterised version is more recent: I think it was introduced around Delphi 7.
It then stops executing that function after first executing any explicit or implicit finally
blocks.
I’ve seen various projects that used their own
Exit
procedure. This is a very bad habit: Since theSystem
unit is always further away in scope, the introduced one is called which can severely confuse programmers not being aware of this.
The code generation for the parameterless and parameterised “overloads” of System.Exit
is slightly different:
- The parameterless one can often be optimised away, for instance folding multiple calls to them into one, or rearranging code execution so a jump isn’t needed any more. This means you cannot always put a breakpoint on them.
- The parameterised one always needs code to load the function result, so you can always put a breakpoint on them.
Stefan Glienke explained the above in [WayBack] The advantage of using Exit() instead of a plain Exit? You can place a breakpoint! – Uwe Raabe – Google+
–jeroen