next up previous contents index
Next: Exception handling nesting Up: Exceptions Previous: The try...except statement

The try...finally statement

A Try..Finally statement has the following form:


Try...finally statement




If no exception occurs inside the statement List, then the program runs as if the Try, Finally and End keywords were not present.

If, however, an exception occurs, the program flow is immediatly transferred from the point where the excepion was raised to the first statement of the Finally statements. All statements after the finally kayword will be executed, and then the exception will be automatically re-raised. Any statements between the place where the exception was raised and the first statement of the Finally Statements are skipped.

As an example consider the following routine:



If during the execution of the file handling an excption occurs, then program flow will continue at the close(F) statement, skipping any file operations that might follow between the place where the exception was raised, and the Close statement.

If no exception occurred, all file operations will be executed, and the file will be closed at the end.


next up previous contents index
Next: Exception handling nesting Up: Exceptions Previous: The try...except statement

Michael Van Canneyt
Fri Sep 25 09:15:40 MEST 1998