2
votes

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?

2

2 Answers

1
votes

Encapsulate your UserControl within an object implementing your plugin interface by simply calling the plugin implementation and adding your try catch logic around each call.

1
votes

you can use a global exception handling (like a custom HTTPModule) And then determine the exception was throw by a which plug in.

take a look to this links, maybe useful
http://www.15seconds.com/issue/030102.htm
http://codebetter.com/blogs/karlseguin/archive/2006/06/12/146356.aspx