title: BackgroundWorker capture error
body: <p>I've been trying to follow this MSDN <a href="http://msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx" rel="nofollow noreferrer">example</a>, and using the code below. However, <code>e.Error</code> is ALWAYS null in RunWorkerCompleted even when an error does occur in SomeMethod();</p>
  
  <pre><code>private void WorkerDoWork(object sender, DoWorkEventArgs e)
  {
     getMethod = SomeMethod();
  }
  
  private void Worker_RunWorkerCompleted(object sender,
                                               RunWorkerCompletedEventArgs e)
  {
      if (e.Error != null)
      {
          var result = ModernDialog.ShowMessage("Error occurred.... " +
                                     e.Result, "ErrorTitle", MessageBoxButton.OK);
      }
      else if (e.Cancelled)
      {
  
      }
      Else
      {
  
      }
  }
  </code></pre>
  
  <p>Can anyone see what I'm doing wrong?</p>
  
  <p>I can get around it by doing the following but I don't really understand why the example in MSDN is not working for me?</p>
  
  <pre><code>private void WorkerDoWork(object sender, DoWorkEventArgs e)
  {
      try
      {
          getMethod = SomeMethod();
      }
      catch(Exception ex)
      {
          e.Result = ex;
      }
  }
  
  private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
  
      if (e.Result is Exception)
      {
              var result = ModernDialog.ShowMessage("Error occurred.... " + e.Result, "ErrorTitle", MessageBoxButton.OK);
      }
  
      //etc
  }
  </code></pre>
  
  <p>Also, using the second method I can't access the .Message from e.Result. For example, in WorkerDoWork I can use <code>ex.Message</code></p>
  
  <p>Edit: I've setup the worker to create it's own error and I still get e.Error == null. The variable displayed is a bit faint as CTRL+PrtSc makes it fade
  <img src="https://i.stack.imgur.com/m85GI.png" alt="enter image description here"></p>