I am writing a WinForms application that accepts dynamic user interface controls, in the form of plugins (think widgets). For this, the main function of each plugin returns a UserControl that is then added to the main form.
Since my application doesn't have direct control over them, I would like to "sandbox" the plugins exception-wise such that if one of the UserControls throws an error, I can catch it and unload the culprit. The obvious trouble is that the UserControls are event driven and can throw exceptions in a million different places, so I don't have one thing to wrap in a try/catch block.
How can I catch the exceptions thrown by dynamic UserControls or what would be a better design for such a modular application?