The finally Block - CSharp Custom Type

CSharp examples for Custom Type:try catch finally

Introduction

A finally block always executes-whether or not an exception is thrown and whether or not the try block runs to completion.

finally blocks are typically used for cleanup code.

StreamReader reader = null;    // In System.IO namespace
try
{
  reader = File.OpenText ("file.txt");
  if (reader.EndOfStream) return;
  Console.WriteLine (reader.ReadToEnd());
}
finally
{
  if (reader != null) reader.Dispose();
}

Related Tutorials