Skip to content
Justice Tech School

try, catch and finally

Handle errors with try and catch. finally always runs.

Example
try
{
    int x = int.Parse("abc");
}
catch (FormatException e)
{
    Console.WriteLine("bad number");
}
finally
{
    Console.WriteLine("done");
}

Exercise

Always runs.

try {}  {}

Quiz Test

Which block always runs?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.