I use a parallel task library to run a task that, if canceled, throws an OperationCanceledException, which is then thrown using the AggregateException as follows. The AggregateException tool contains a list of TaskCanceledExceptions that correspond to thrown exceptions. Unfortunately, these TaskCanceledExceptions seem to lose stack traces caused by the original exceptions. Is it for design?
try { task1.Wait(); } catch (AggregateException aggEx) { var tcex = ex as TaskCanceledException; if (tcex != null) { Debug.WriteLine("InnerException:{0}, Message:{1}, Source:{2}, StackTrace: {3}", tcex.InnerException, tcex.Message, tcex.Source, tcex.StackTrace); return true; } else { return false; } }
Result:
InnerException:, Message:A task was canceled., Source:, StackTrace:
source share