public async Task HandleAsyncAfter(AsyncResource resource, bool throwException) { try { await resource.OpenAsync(throwException); } catch (Exception exception) { await resource.LogAsync(exception); } finally { await resource.CloseAsync(); } }
private static async Task HandleAsyncBefore(AsyncResource resource, bool throwException) { Exception exceptionToLog = null; try { await resource.OpenAsync(throwException); } catch (Exception exception) { exceptionToLog = exception; } if (exceptionToLog != null) { await resource.LogAsync(exceptionToLog); } }