Locked lesson.
About this lesson
The Finally part of Exception Handling will ensure specific code runs after try / catch blocks.
Exercise files
Download this lesson’s related exercise files.
41 - Finally Exception Handling.docx61 KB 41 - Finally Exception Handling SOLUTION.docx
59.2 KB
Quick reference
Finally Exception Handling
Finally allows you to continue with your code after the try/catch blocks, regardless of the exception.
When to use
Use this when you aren't really sure what exception is going to be thrown.
Instructions
try
{
string[] names = {"John", "Mary", "Tim"};
Console.WriteLine(names[27]);
}
catch
{
Console.WriteLine("Error");
}
finally
{
Console.WriteLine("Continue on with your code...");
}
Hints & tips
- Finally allows your code to continue on after the exception.
Lesson notes are only available for subscribers.