Zest.

C#: try / catch

A short, tested C# example for try / catch. Copy it and adjust the names and paths for your project.

C#
try
{
    var n = int.Parse(input);
}
catch (FormatException ex)
{
    Console.WriteLine($"Not a number: {ex.Message}");
}
finally
{
    Console.WriteLine("done");
}

Find it in Zest

Search for “csharp try / catch” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More C# examples

All C# examples