3 ms·
For completeness, isn't there a third option of ensuring you're catching and handling all exceptions in an async void handler? private static async void OnT
by jongalloway2 11y ago
For completeness, isn't there a third option of ensuring you're catching and handling all exceptions in an async void handler?
private static async void OnTimerFired(object sender, ElapsedEventArgs args)
{
Exception exception = null;
try
{
await Task.Delay(1000);
// this is NOT going to terminate your process!
throw new Exception();
}
catch (Exception ex)
{
exception = ex;
}
if (exception != null)
{
...
}
}
And in C#6 you can await in catch or finally blocks, so this gets even simpler.