title: AggregateException C# example
body: <p>I have seen an example of <code>AggregateException</code> on the web and I'm trying to figure out how it works. I have written a simple example, but my code for some reason doesn't work.</p>
  
  <p>Could someone explain to me what the problem is?</p>
  
  <pre><code>public static void Main()
  {
      try
      {
          Parallel.For(0, 500000, i =&gt;
          {
              if (i == 10523)
                  throw new TimeoutException("i = 10523");
              Console.WriteLine(i + "\n");
          });
      }
      catch (AggregateException exception)
      {
          foreach (Exception ex in exception.InnerExceptions)
          {
              Console.WriteLine(ex.ToString());
          }
      }
  }
  </code></pre>