Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:30:37+00:00 2026-06-09T20:30:37+00:00

In this code: private async void button1_Click(object sender, EventArgs e) { try { await

  • 0

In this code:

private async void button1_Click(object sender, EventArgs e) {
    try {
        await Task.WhenAll(DoLongThingAsyncEx1(), DoLongThingAsyncEx2());
    }
    catch (Exception ex) {
        // Expect AggregateException, but got InvalidTimeZoneException
    }
}

Task DoLongThingAsyncEx1() {
    return Task.Run(() => { throw new InvalidTimeZoneException(); });
}

Task DoLongThingAsyncEx2() {
    return Task.Run(() => { throw new InvalidOperation();});
}

I expected WhenAll to create and throw an AggregateException, since at least one of the tasks it was awaiting on threw an exception. Instead, I’m getting back a single exception thrown by one of the tasks.

Does WhenAll not always create an AggregateException?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:30:39+00:00Added an answer on June 9, 2026 at 8:30 pm

    I don’t exactly remember where, but I read somewhere that with new async/await keywords, they unwrap the AggregateException into the actual exception.

    So, in catch block, you get the actual exception and not the aggregated one. This helps us write more natural and intuitive code.

    This was also needed for easier conversion of existing code into using async/await where the a lot of code expects specific exceptions and not aggregated exceptions.

    — Edit —

    Got it:

    An Async Primer by Bill Wagner

    Bill Wagner said: (in When Exceptions Happen)

    …When you use await, the code generated by the compiler unwraps the
    AggregateException and throws the underlying exception. By leveraging
    await, you avoid the extra work to handle the AggregateException type
    used by Task.Result, Task.Wait, and other Wait methods defined in the
    Task class. That’s another reason to use await instead of the
    underlying Task methods….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: private void timer1_Tick(object sender, EventArgs e) { #region BaseAddress Process[]
With this code: private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) { const int TICKETSOURCE_COLUMN =
I am using silverlight 4, and the new async CTP. private void button1_Click(object sender,
I have this code private void writeReport(IReport report, string reportName) { string reportString =
Must be a way looping through this code: private void loadSprites() { this.sprites[0] =
this is my code private void sendToClient(Dictionary<string, string> reportDic) { Response.Clear(); Response.BufferOutput = false;
I have this piece of code: private void myFunc(){ obj = doSomething(); //If value
I have a problem with async-await expression which returns wrong result. private Task<int> A
I got a code for calling async blocks. private delegate void MyDelegate(); void Async(MyDelegate
I currently have this code : Private Sub Worksheet_Change(ByVal Target As Range) Dim lastrow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.