Chapter 17
Exceptions

Exceptions provide a convenient way to program error and error-recovery mechanisms, and are closely related to classes. Exception support is based on three constructs:

_________________________________________________________________________________________________________
Exception

--                --                -----------------------------
  exception-statement  -try- except- statement|
                   -tryr- fianisaell- sy-t sattaetmeemnetnt|
___________________________________________________________________

Raise statement
To raise an exception. This is usually done to signal an error condition. It is however also usable to abort execution and immediately return to a well-known point in the executable.
Try ... Except statement
This is a structured statement. This block of statements serve to catch exceptions raised within the scope of the block, and to provide exception-recovery code.
Try ... Finally statement
Is also a structured statement. This block of statements force code to be executed irrespective of an exception occurrence or not. They generally serve to clean up memory or close files in case an exception occurs. The compiler generates many implicit Try ... Finally blocks around procedure, to force memory consistency.

Remark Because exceptions use classes, you need one of the object pascal modes to be able to use them:

{$MODE OBJFPC}

Or

{$MODE DELPHI}

 17.1 The raise statement
 17.2 The try...except statement
 17.3 The try...finally statement
 17.4 Exception handling nesting
 17.5 Exception classes