Tsallaka zuwa abun ciki
Justice Tech School

C# Exceptions

try runs risky code, catch handles an error and finally always runs. Catch specific exceptions and throw your own with throw new.

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

Exercise

Always runs.

try {} catch {}  {}

Quiz Test

When does finally run?

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