Using Visual Studio 2015, targeting FW 4 (testing unobservable exceptions under FW 4):
I'm expecting this code:
static void Main(string[] args)
{
try
{
Task.Factory.StartNew(() => Console.WriteLine(1))
.ContinueWith(t => Thread.Sleep(1000))
.ContinueWith(t => Console.WriteLine(2))
.ContinueWith(t => Thread.Sleep(1000))
.ContinueWith(t => { throw new Exception("aaaa"); })
.ContinueWith(t => Console.WriteLine(3));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
GC.Collect();
GC.Collect();
Console.ReadLine();
}
To show me the exception.
I know I can see it via T.Wait()
or in the last task with t.Exception
- but why am I not seeing the exception here?
I know that the exception handling mechanism was changed in 4.5 and in order to get the old mechanism I should add:
<ThrowUnobservedTaskExceptions enabled="true"/>
Which I did:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<ThrowUnobservedTaskExceptions enabled="true"/>
</runtime>
</configuration>
But still the result is:
Question:
Why don't I see the exception?
Worth a mention that I do see the exception in debug mode: