c# - Unhandled Exception raised in ContinueWith not caught/handled in global handler -


There are global exception handlers in my application (well, loggers, I know they do not technically "handle" Some of the things that are:

  Public static classes unrestricted expedition handler {public static zero Init ({{AppDomain.CurrentDomain.UnhandledException + = OnCurrentDomainOnUnhandledException; Application.SetUnhandledExceptionMode (UnhandledExceptionMode.CatchException); Application.ThreadException + = ApplicationOnThreadException; } Private static zero ApplicationOnThreadException (Object Sender, ThreadExceptionEventErgase E) {if (e.Exception! = Null) MessageBox.Show (e.exception.ToString ()); } Private static blank oncurrentadmanAnandled expansion (Object Sender, Unlimited Excessive Avenger ARGS E) {var ex = e.ExceptionObject as an exception; If (ex! = Null) MessageBox.Show (ex.ToString ()); }}  

has main ()

  unhandledExceptionHandler.Init ();  

But I think when unwanted exceptions occur within one task. Continue with these events is not raised. Visual Studio is recognized as unhappy because they are highlighted in the debugger. For example, you can test it with the bus:

  Private Zero Button 1_Click (Object Sender, EventArgs) {Task. Factor STARTNU (() => ({}). COMPLETE (T = & gt; {Throw New Exception ("Continue with Exception");}); }  

You will see that no messagebox has been picked (nor is one of the events).

To prove this simply works, the following will work:

  Private Zero Button 2_Click (Object Sender, EventArgs E) {new exception throw ("Failed Click");   

I appreciate it That it could possibly understand a minimum to keep the volume of logic inside ContinueWith, but it can still be done.

From the comments currently: .NET 4.0

It's a shame that I only have to work to continue with one operation

You do not have to do this. Simply use the then pattern by Stephen Toub. Also, be sure to read it, it will help you better understand the behavior you are seeing.

He said, you can seriously consider using the async / await code with VS2012 and you continue You can forget about and use the natural / code / handle to handle exceptions.


Comments