How to handle Async Exceptions?

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric




You probably use Async-methods, but you don’t like the way how exceptions are handled? Remember, the async exception is typically an AggregatedException. In this case you have to dig into the list of exceptions etc., etc.

Following peace of code shows how you can implement a very simple handler method, which grabs the right exception from the list of exceptions.

(() => YourMethodAsync().Result);

   . . .

 public static T AsyncExceptionHelper<T>(Func<T> method){

           T retObj = default(T);
                retObj = method();

            catch (AggregateException exception)


            return retObj;

Posted Jan 27 2015, 07:34 AM by Damir Dobric
Filed under: is a .Net Community Blog powered by daenet GmbH.