Lecture overview -- Keyboard shortcut: 'u'  Previous page: Raising and throwing exceptions in C# -- Keyboard shortcut: 'p'  Next page: Rethrowing an exception -- Keyboard shortcut: 'n'  Lecture notes - all slides together  Annotated slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Alphabetic index  Help page about these notes  Course home    Exception Handling - slide 24 : 30

Try-catch with a finally clause
A finally part of a try statement ensures a given code block is executed both in case of success and failure of the try-block
try
  try-block
catch (exception-type name)
  catch-block
...
finally
  finally-block
A try-finally control structure is sometimes used - without catch clauses - to ensure execution of the finally-block in cases the control leave the try-block abruptly
prog.cs
Illustration of try-catch-finally.
output
Output from the try-catch-finally program.