C# - Task Exception not being caught
<p>I am sure I am doinig something wrong, but when I try this example of the new threading task exception handling I keep getting the exception unhandled by user code.  The whole point of the code is to show an example of how to catch errors in tasks. </p>

<p>Link: <a href="http://msdn.microsoft.com/en-us/library/dd997415.aspx" rel="nofollow">Task Exception Example</a></p>

<pre><code>static void Main(string[] args)
        {
            var task1 = Task.Factory.StartNew(() =&gt;
            {
                throw new MyCustomException("I'm bad, but not too bad!");
            });

            try
            {
                task1.Wait();
            }
            catch (AggregateException ae)
            {
                // Assume we know what's going on with this particular exception. 
                // Rethrow anything else. AggregateException.Handle provides 
                // another way to express this. See later example. 
                foreach (var e in ae.InnerExceptions)
                {
                    if (e is MyCustomException)
                    {
                        Console.WriteLine(e.Message);
                    }
                    else
                    {
                        throw;
                    }
                }

            }
        }
</code></pre>

<p>Most likely user error just not sure what (Using Visual Studio 2012);</p>
