The keyword is used to mark the start of the final block of statements in a Finally Try statement. They are executed regardless of what happens in the Try statements.
However, the clause does not actually handle any exceptions - the program will terminate if no Except clause is found (see notes below).
Try-Finally is normally used by a routine to allow cleanup processing to take place, such as freeing resources, with the exception being correctly passed to the caller to handle.
There are times when you want a construct like this :
where exceptions are trapped and acted upon, but in all cases, a set of clean up statements are executed. This can be achieved with nested Try statements :
Starts the error trapping clause of a
Defines exception handling in a
Try Except clause
Raise an exception
Starts code that has error trapping
Buy Website Traffic at Buywebsitetrafficexperts.com
Buy Proxies at Buyproxies.io
this web site as a Windows program.
Example code : Zero divide with a finally clause
number, zero : Integer;
begin // Try to divide an integer by zero - to raise an exception
number := -1;
zero := 0;
number := 1 div zero;
ShowMessage('number / zero = '+IntToStr(number));
if number = -1 then
ShowMessage('Number was not assigned a value - using default');
number := 0;
Show full unit code
Number was not assigned a value - using default
Then, the program terminates with an EDivByZero error message - the finally clause did not trap the error.