-
Missing Item Issue
I have a plugin system that dynamically loads dlls. This is under construction, so I occasionally make changes that break a plugin because I added/altered/removed some member of an interface. This has some interesting results.
There are some events raised by various objects that can be handled by plugins. In one such case, the handler in the plugin had a problem. The exact problem was that it referenced something that wasn't available. The event handler had a couple nested If statements, and only if those were all true did it reach the code that referenced the missing library. I was rather hoping that a breakpoint on one of the outer If statements would be reached, but that's not the case.
I suppose that's understandable, as the method compiles into something that references the missing library, so it never does manage to compile that method correctly. However, the object that has the event handler compiled without issue (I know why that is, and it isn't quite relevant), so I was able to use the dll. To get to the point where the event could be handled (and fail), an instance of the object had to be created. This worked without issue. It's only when the event handler ran that it threw an exception.
An exception handler wrapped around the code in the event handler won't do a thing, because it won't be reached. An exception handler around the RaiseEvent that raised the event is too early. It works well enough for logging that something happened, but there could be several objects handling the same event. Once one of them fails, none of the subsequent event handlers even get attempted.
Since the code is in a dll, I can't create an application event handler, as far as I can determine, but that's kind of what I need to do.
The goal is that, if an event is raised that will be handled by several different objects, if one of the objects throws an exception, the other event handlers will still run. For some exceptions, that would be easy, because the event handler code could be wrapped in an exception handler (or could just not throw an exception), but in this case, the exception happens before the event handler appears to be entered. Is there any way to handle such an exception such that any other subscribers to the event will still get a chance to handle the event?