finally Block
noun
say it: “FY-nuh-lee blok” /ˈfaɪnəli blɒk/
A block after try and catch that runs whether or not an exception happened.
What is finally Block in C#?
finally Block — A block that normally runs after try and catch whether an exception occurred or not.
class OrderReader
{
int ReadQuantity(string text)
{
try
{
return int.Parse(text);
}
catch (FormatException)
{
return 0;
}
}
}
In a sentence
- “The finally block closes the file even when reading fails.”
Level: Journeyman · More C# terms at this level
Updated