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();
}