Global Exception Handler

Is there any equivalent to the global exception handler in the microframework? If an unhandled exception occurs I need the system to reboot, not crash and stop running. I can’t have a device in the field waiting for someone to “press the reset button”. I need this system to be able to recover without human intervention. Any ideas?

Will wrapping all of the code in your Main method in an exception handler perform the same function?

You may need to do the same for any threads.


Thanks for the advice. I was so focused on trying to find the equivalent of the standard .NET global handler that I didn’t think to try that.

A follow up question… is there a way to print the call stack or at least the name of the function that threw the exception in the microframework. It looks like the full .NET implementation has a callstack feature that the microframework does not. I’m hoping I just haven’t found the equivalent function call for System.Diagnostics.StackTrace().

Not sure if you have already handled this but to go along with what Nevyn was saying…

something along the lines of this might help depending on your flow.

        catch (Exception e)
            if (e == REQUIRES_REBOOT_EXCEPTION)//However you determine the system should reboot
                //You could inspect the exception here.
                // It is not a stack trace but could provide some info
                var ie = e.InnerException;
                while(ie !=null)
                      ie = ie.InnerException;

                //There is another overload in case you have listeners to the OnRebootEvent