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

  • Home
  • SEARCH
  • 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 8902989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:45:18+00:00 2026-06-15T01:45:18+00:00

I am trying to convert an application to use Tasks instead of Microsoft’s multithreaded

  • 0

I am trying to convert an application to use Tasks instead of Microsoft’s multithreaded framework, but I’m having trouble with the error handling. From Microsoft’s documentation ( http://msdn.microsoft.com/en-us/library/vstudio/0yd65esw.aspx ), I would expect the try-catch below to catch the exception:

private async void Button1_Click()
{
    try
    {
        object obj = await TaskFunctionAsync()
    }
    catch(Exception ex)
    {}
}

public Task<object> TaskFunctionAsync()
{
    return Task.Run<object>(() =>
    {
        throw new Exception("foo");
        return new object();
    });
}

but when Button1_Click is fired, I get an unhandled exception within the lambda expression. Is there some way to get the exception out into the try-catch? I thought that this kind of error handling (so you don’t need to marshal from the task worker thread) was one of the major benefits of the Task framework.

I’ve also tried:

public async Task<object> TaskFunctionAsync()
{
    return await Task.Run<object>(() =>
        {
            throw new Exception("foo");
            return new object();
        });
}
  • 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-15T01:45:19+00:00Added an answer on June 15, 2026 at 1:45 am

    but when Button1_Click is fired, I get an unhandled exception within
    the lambda expression

    That’s not true. It is unhandled by user-code because the framework catches it, but not completely unhandled. Continue running the application to see that the exception will be caught by the catch in Button1_Click.

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

Sidebar

Related Questions

I'm trying to use Hibernate in my Spring application but i've got an error
I'm trying to convert an ASP.NET web application to use resource files. I haven't
I am trying to convert my Android application to use the LoaderManager and CursorLoader.
I am trying to use Informix database with a Play! Framework application. I am
Where I was I'm trying to convert some WCF services to use ServiceStack instead.
I am trying to convert an application I support from application.cfm to application.cfc. I
I am new to ASP.NET and am trying to convert a web application from
I have an application in C# that I'm trying to convert to java. The
I have a Groovy application for Windows and am trying to convert a Hash
i'm trying to convert my log4j.properties into log4j.xml because i need to use some

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.