title: Exception Handling : AOP vs Classic Handling?
body: <p>I'm upgrading a <strong>Plugin Loading Engine</strong> (<code>.NET</code>) which does the following :</p>
  
  <ol>
  <li>Loads Plugins</li>
  <li>Connects them to the appropriate Data Source</li>
  <li>Launchs the Plugins</li>
  <li>Displays the results</li>
  </ol>
  
  <p>All the plugins implement the same Interface : <code>IPlugin</code>and each one is launched in a separate <code>BackGroundWorker</code>. All the <code>BackgroundWorkers</code> are managed by a module called <code>Host</code>.</p>
  
  <p>My problem is the <code>Errors/Exceptions Handling</code>.  The engine is already deployed and I want to find an elegant way to handle the <code>Errors/Exceptions</code> that could be thrown when the plugins run. Some <code>Exceptions</code> are caught in the plugins but not all of them.</p>
  
  <p>I was thinking about a separate layer that could catch the errors and treat them for all the plugins.  </p>
  
  <p>I imagined a kind of <code>Context</code> attached to each <code>Plugin</code> which contain its progress level (<code>BackgroundWorker.ReportProgress</code>), its status, the thrown exceptions(using the <code>RunWorkerCompletedEvent</code>) but the errors are thrown only after the <code>BackgroundWorker</code> stops. I would like to interrupt it when an exception is thrown.  </p>
  
  <p>I was also thinking that Aspect Oriented Programming could be a great way. I took a look on the net and found some framework like <strong>Spring.NET</strong>. But not sure if it could be appropriate in my case.  </p>
  
  <p><strong>[UPDATE]</strong>
  Here are more design details as requested : </p>
  
  <ul>
  <li>IPlugin Interface : Called <code>AbstractEnvChecker</code> :</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/qM25H.jpg" alt="AbstractEnvChecker"></p>
  
  <p>The application is a <strong>Rich Client App</strong>. After compiling the plugins, the generated <code>DLL</code> are loaded and a List is displayed to the users in a simple Windows Form. The user selects then the plugins to launch and the <code>Plugin.DoWork()</code> method is called.</p>
  
  <p>And here is how the <strong>Host</strong> launches the selected Plugins :</p>
  
  <pre><code>void LaunchPlugin(AbstractEnvChecker p_Plugin)
  {
      if (p_Plugin != null)
      {
          BackgroundWorker l_BackgroundWorker = new BackgroundWorker();
          l_BackgroundWorker.WorkerReportsProgress = true;
          l_BackgroundWorker.WorkerSupportsCancellation = true;
  
          l_BackgroundWorker.DoWork +=
              new DoWorkEventHandler(bw_DoWork);
          l_BackgroundWorker.ProgressChanged +=
              new ProgressChangedEventHandler(bw_ProgressChanged);
          l_BackgroundWorker.RunWorkerCompleted +=
              new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
  
          m_PluginByThreadMap.Add(l_BackgroundWorker, p_Plugin);
          l_BackgroundWorker.DoWork += p_Plugin.DoWork;
          l_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(l_BackgroundWorker_RunWorkerCompleted);
          l_BackgroundWorker.RunWorkerAsync(p_Plugin);
      }
  }
  </code></pre>
  
  <p>Is <code>AOP</code> an appropriate solution to add the Error Handling Layer ?</p>