C# 14 · Async, errors and resources

Handle exceptions

Catch specific exceptions, filter with when, and clean up in finally.

try
{
    Process(file);
}
catch (IOException ex) when (ex.HResult != 0)
{
    Console.Error.WriteLine(ex.Message);
}
finally
{
    Cleanup();
}

Official C# 14 documentation

More async, errors and resources commands

All async, errors and resources commands · C# 14 cheatsheet

Was this page helpful?