title: Exception tracking in Multi-Threaded C# using Tasks
body: <p>I'm running a method for a list of inputs; this list is provided by the user. If an exception happens in processing one input, I have to remove that from the output table.  The code looks something like this:</p>
  
  <pre><code>List&lt;Task&gt; methodsList = new List&lt;Task&gt;();
  for (int i = 0; i &lt; inputList.Count; i++)
  {
      int arg = i;
      Task newTask = Task.Factory.StartNew(() =&gt; ProcessInput(i));
      methodsList.Add(newTask);
  }
  if (methodsList.Count != 0)
  {
      try
      {
          Task.WaitAll(methodsList.ToArray());
      }
      catch (AggregateException ex)
      {
          foreach (Exception innerEx in ex.InnerExceptions)
          {
              throw innerEx;
          }
      }
  }
  </code></pre>
  
  <p>The problem is that when I wait for all the tasks to finish, the <strong>AggregatedException</strong> does not give me any information about which thread was failed. I was thinking about handling this by creating a collection and adding the index of finished processes to that list and checking it at the end to see which inputs where not processed, but I was wondering if there is an easier way of doing it.</p>