async/await exception handling pattern

I don’t see why it wouldn’t work, assuming GetContacts is an async method:

public async Task<T> CheckForExceptionAsync<T>(Task<T> source)
{
  try
  {
    return await source;
  }
  catch (Exception ex)
  {
    HandleException(ex);
    return default(T);
  }
}

On a side note, you should avoid async void (as I describe in my MSDN article) and end your async method names with the Async suffix.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)