Samples: Extensible calculator fails at managing exceptions

Jun 5, 2009 at 11:18 PM
Edited Jun 6, 2009 at 3:35 AM

See linked picture.

Is the calculator which handles unhandled exceptions supposed to crash?

Edit: Answering myself; there doesn't seem to be a way on the CLR to catch exceptions and keep the application from crashing.

Jun 8, 2009 at 8:08 PM

Yeah, it seems that the default CLR 2 policy undermines one of the potentially coolest things about MAF: to be able to unload/reload an AppDomain that has an unhandled exception.

Part of the reason for the change in policy, and a description of changes coming in CLR 4, is here in this excellent article: http://msdn.microsoft.com/en-us/magazine/dd419661.aspx

I corresponded a bit with Andrew Pardoe (the author of that article) and he said this:

"Thanks, I’m glad you liked the article. There’s been a healthy discussion about this on our CLR Team blog at http://blogs.msdn.com/clrteam.

You can use the CLR Hosting APIs (http://msdn.microsoft.com/en-us/library/ms164400.aspx) to set the unhandled exception policy. The default policy is to tear down the process which is the safest action to take if the process has potentially been corrupted.

I can see that there’s not a good way to tell from the AppDomain.UnhandledExceptionNotification whether the exception that was uncaught was a CSE or not. I’ll follow up with the team about that."

I haven't had a whole lot of luck with the suggested work-around, though.  If anyone else gets it working, I'd love to hear about it!

--Stephen