dotnet / dotnet/dotnet-api-docs

Ordering of exceptions in AggregateException not specified

Open
#1,178 0 comments 0 reactions 0 assignees View on GitHub
area-System.Threading.Tasks dotnet-api/prod Pri2 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

Hi,

When I `await` an ordered list of `Task` using `Task.WhenAll()`, I want to be able to rely in my code on the ordering of exceptions in the resulting `AggregateException`. In particular, I want to know what happens if the second `Task` I pass faults prior to the first `Task` I pass: will the returned `AggregateException` always list the exception from the first `Task` I passed first or is it possible for the exception from the second `Task` I passed to preceed the exception from the first `Task` I passed?

If the behavior is undefined or implementation defined, please document that. If the order can be relied upon, please document that.

The text that I am reading is:

> If any of the supplied tasks completes in a faulted state, the returned task will also complete in a [`Faulted`](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskstatus?view=netframework-4.7.2#System_Threading_Tasks_TaskStatus_Faulted) state, where its exceptions will contain the aggregation of the set of unwrapped exceptions from each of the supplied tasks.

In the above text, I see no discussion of the ordering of passed in `Task`s wrt the ordering of exceptions within the `AggregateException`. However, just below it, I see text discussing the ordering of the result array for when all tasks successfully run to completion.

Thanks.

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: db7b0ad3-c574-7956-3a5d-f70ea7689a42
* Version Independent ID: 646e4b02-2f82-5942-62f7-cf5d26b9e213
* Content: [Task.WhenAll Method (System.Threading.Tasks)](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.whenall?view=netframework-4.7.2)
* Content Source: [xml/System.Threading.Tasks/Task.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Threading.Tasks/Task.xml)
* Product: **dotnet-api**
* GitHub Login: @dotnet-bot
* Microsoft Alias: **dotnetcontent**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.