Async and AggregateException
this post is a complementary to Eran Stiller’s post.
I was reading Eran Stiller’s post about exception handling using async methods and I want to add a few side notes.
1) the exception handling behavior decisions is well documented in this post (by the TPL team), it decided after they had consider different options.
2) I was suggesting that compiler will check whether the a catch of AggregateException is implemented and if so to avoid the unwrapping behavior.
in this case the it can be assumed that programmer do expect multiple exceptions.
unfortunately, for the current version, I was speaking with them after the release of .NET 4.5.
I hope that we will see this mitigation in future release.
3) for the current version you can use the following work around if you do want to catch aggregate exception:
by re-throwing the exception the unwrapped exception will be AggregateException.
it may be wise to wrap this pattern in an extension method because it can be a very repetitive one.
Eran is one of my colleague and definitely one of the more talent Architect I was happened to work with.