Main Site Documentation

Global exception handling in the Micro Framework?


In the desktop framework it’s easy enough to set up global exception handling using AppDomain.UnhandledException, but this is not available in NetMF.

When an unhandled exception occurs I’d like to log it before the application terminates.

And it also makes me wonder, what happens when an application on a device terminates?
Does it restart automatically ?


There is no event to process unhandled exceptions, if that is what you’re asking. Assuming your program exits from Main(), you can just wrap it in a try/catch, essentially making all exceptions handled. Note that other threads should handle their own exceptions.

No. I’m not sure exactly what state the board is left in, however. Can someone else chime in?


If you want the board to reset automaticaly when “something fail” you shall investigate the use of the “Watchdog” which is dedicated to that purpose. Just have a timer or a thread update the watchdog timer on a regular basis ; if it fails updating it, then the boards restarts. You will find examples in the beginner’s guide :slight_smile: