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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:53:48+00:00 2026-06-03T03:53:48+00:00

I want to handle exceptions that happen inside of DoWork handler in my RunWorkerCompleted

  • 0

I want to handle exceptions that happen inside of DoWork handler in my RunWorkerCompleted handler but while code is running under debugger I’m getting another exception first “Exeption was unhandled by user code”.

Here short example of code I’m using:

BackgroundWorker _worker;
public void Test()
{
    _worker = new BackgroundWorker();
    _worker.WorkerReportsProgress = false;
    _worker.WorkerSupportsCancellation = false;

    _worker.DoWork += new DoWorkEventHandler(bw_DoWork);
    _worker.RunWorkerCompleted += new
        RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
    _worker.RunWorkerAsync();
}

private void bw_DoWork(object sender, DoWorkEventArgs e)
{
    e.Result = ActuallWorkHere();
}

private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    var t = e.Error;
}

private IEnumerable<string> ActuallWorkHere()
{
    throw new Exception("test");
    // "Exeption was unhandled by user code" if called
    string[] res = { "test" };
    return res;
}

What am I doing wrong?

  • 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-03T03:53:49+00:00Added an answer on June 3, 2026 at 3:53 am

    You’re not really doing anything wrong, this is what Visual Studio does with unhandled errors when running code in the debugger:

    From BackgroundWorker.DoWork Event on MSDN:

    If you are running under the Visual Studio debugger, the debugger will
    break at the point in the DoWork event handler where the unhandled
    exception was raised.

    Try running your compiled program and you won’t see this.

    Note that you can handle this exception in your DoWork and the RunWorkerCompletedEventArgs.Error property in your RunWorkerCompleted handler will still store details of your error.

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

Sidebar

Related Questions

I want to use Oracle exception to handle errors that might happen in the
i want to handle the tab keypress in such a way that if there
So I want to have tabs with default style but I want to handle
I want to write an IErrorHandler implementation that will handle AuthenticationException instances (a proprietary
I have some framework / AOP code that logs exceptions from methods called deeper
I want to handle the keydown event globally in my application and as such
I want to handle events on a treeview with ACB ( http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/ ). I
I have an input box which I want to handle two types of information,
I have an ATL app where I want to handle WM_POWERBROADCAST . I have
I'm working on a project and we want to handle our logging using log4j.

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.