Getting a meaningful stack trace when using async code
So – is there any way to get a more meaningful stack trace when running async tasks? Yes, you can use ExceptionDispatchInfo.Capture that was introduced in .NET 4.5 for async-await speficially: private static void ThrowError(Task t) { if (t.IsFaulted) { Exception exception = t.Exception.InnerExceptions != null && t.Exception.InnerExceptions.Count == 1 ? t.Exception.InnerExceptions[0] : t.Exception; ExceptionDispatchInfo.Capture(exception).Throw(); … Read more