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 4084202
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:24:35+00:00 2026-05-20T18:24:35+00:00

Using the async CTP from Microsoft for .NET, is it possible to catch an

  • 0

Using the async CTP from Microsoft for .NET,
is it possible to catch an exception thrown by an async method in the calling method?

public async void Foo()
{
    var x = await DoSomethingAsync();

    /* Handle the result, but sometimes an exception might be thrown.
       For example, DoSomethingAsync gets data from the network
       and the data is invalid... a ProtocolException might be thrown. */
}

public void DoFoo()
{
    try
    {
        Foo();
    }
    catch (ProtocolException ex)
    {
          /* The exception will never be caught.
             Instead when in debug mode, VS2010 will warn and continue.
             The deployed the app will simply crash. */
    }
}

So basically I want the exception from the async code to bubble up into my calling code
if that is even possible at all.

  • 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-05-20T18:24:36+00:00Added an answer on May 20, 2026 at 6:24 pm

    It’s somewhat weird to read but yes, the exception will bubble up to the calling code – but only if you await or Wait() the call to Foo.

    public async Task Foo()
    {
        var x = await DoSomethingAsync();
    }
    
    public async void DoFoo()
    {
        try
        {
            await Foo();
        }
        catch (ProtocolException ex)
        {
              // The exception will be caught because you've awaited
              // the call in an async method.
        }
    }
    
    //or//
    
    public void DoFoo()
    {
        try
        {
            Foo().Wait();
        }
        catch (ProtocolException ex)
        {
              /* The exception will be caught because you've
                 waited for the completion of the call. */
        }
    } 
    

    As Stephen Cleary wrote in Async/Await – Best Practices in Asynchronous Programming:

    Async void methods have different error-handling semantics. When an exception is thrown out of an async Task or async Task method, that exception is captured and placed on the Task object. With async void methods, there is no Task object, so any exceptions thrown out of an async void method will be raised directly on the SynchronizationContext that was active when the async void method started.

    Note that using Wait() may cause your application to block, if .NET decides to execute your method synchronously.

    This explanation http://www.interact-sw.co.uk/iangblog/2010/11/01/csharp5-async-exceptions is pretty good – it discusses the steps the compiler takes to achieve this magic.

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

Sidebar

Related Questions

I am using silverlight 4, and the new async CTP. private void button1_Click(object sender,
I am using async sockets in my project. When i calling Disconnect method in
The await keyword in C# (.NET Async CTP) is not allowed from within a
When writing async method implementations using the BeginInvoke/EndInvoke pattern the code might look something
$.ajax({ url: /cgi-bin/stats.exe, method: post, async: false, data: { refresh: a41 } }); Using
I am trying to do async IO using BeginRead() in JScript.NET, but I can't
When using async download methods and delegates, is it possible to start multiple simultaneous
I've used async methods today, calling methods asynchronously and using the caller's callback methods.
I asynchronously invoke a method with Spring, using @Async . This method invokes another
Friends, onCreate() I am loading data from webservice using Async thread. when thread is

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.