I studied this article on MSDN , as well as some questions / answers on SO on this topic, but I canโt understand why the code below does not work (in the example, a console application).
It is expected that the result will establish that an AggregateException indicates that MSDN will contain one internal exception with a hello message. Instead, the hello exception is not handled. This happens when inside the debugger.
If you click continue or run offline, it will work as expected. Is there any way to avoid clicking continue all the time in VS? In the end, everything inside the Try...Catch block is considered processed in a single-threaded programming model. Otherwise, debugging can be a nightmare.
Vb.net
Sub Main() Try Task.Factory.StartNew(AddressOf TaskThatThrowsException).Wait() Catch ex As AggregateException Console.WriteLine(ex.ToString) 'does not get here until you hit Continue End Try End Sub Private Sub TaskThatThrowsException() Throw New Exception("hello") 'exception was unhandled End Sub
FROM#
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { try { Task.Factory.StartNew(TaskThatThrowsException).Wait(); } catch (AggregateException ex) { Console.WriteLine(ex.ToString());
Is there something obvious I'm missing here?
Neolisk
source share