title: Why can an Exception not be rethrown in the BackgroundWorker RunWorkerCompleted event
body: <p>I've checked through some posts on this topic which cover <strong>how</strong> to get around this issues, but I can't quite understand the <strong>Why</strong> of this odd behaviour?</p>
  
  <p><strong><em>Short version</em></strong>:</p>
  
  <p>Why is are <code>Exception</code>s thrown inside the <code>RunWorkerCompleted</code> event not caught by the calling code?</p>
  
  <p><strong><em>Detailed version</em></strong>:</p>
  
  <ul>
  <li>I have a <code>BackgroundWorker</code> (BGW from now on).</li>
  <li>The BGW's <code>DoWork</code> event throws an <code>Exception</code></li>
  <li>The BGW's <code>RunWorkerCompleted</code> event catches the <code>Exception</code>, logs and does some cool cleanup work.</li>
  <li>After cleanup up, the <code>RunWorkerCompleted</code> event <em>re-throws</em> the <code>Exception</code>.</li>
  </ul>
  
  <p>If the <code>RunWorkerCompleted</code> event runs on the Main thread, wouldn't that mean that the calling code (also on the main thread) should be able to catch that exception?</p>
  
  <p>Some code to reinforce the concept...</p>
  
  <pre><code>private void SomeMethod()
  {
      BackgroundWorker bgw = new BackgroundWorker();
      bgw.DoWork += bgw_DoWork;
      bgw.RunWorkerCompleted += bgw_RunWorkerCompleted;
      bgw.RunWorkerAsync();
  }
  
  private void bgw_DoWork(object sender, DoWorkEventArgs e)
  {
      throw new Exception("Oops");
  }
  
  private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
      if(e.Error != null)
      {
          // Log exception &amp; cleanup code here...
          throw e.Error; // Always unhandled :(
      }
  }
  </code></pre>
  
  <p>I would assume that calling <code>SomeMethod</code> like this would would catch the <code>Exception</code> and show the Message Box, but the BGW doesn't behave as I expected and the <code>Exception</code> always remains unhandled...</p>
  
  <pre><code>try
  {
      SomeMethod();
  }
  catch (Exception)
  {
      MessageBox.Show("Handled exception");
  }
  </code></pre>