I have overridden the OnUnhandledException in my bootstrapper, but in the following scenario it is not called:
public class Foo : IHandle<Bar> {
public void Handle(Bar message) {
// Do something that requires UI thread
}
public void DoSomething() {
eventAggregator.PublishOnBackgroundThread(new Bar());
}
}
When the handle method is called it will throw InvalidOperationException: The calling thread must be STA, because many UI components require this.
because it is performed on the background thread instead of on the UI thread:
That exception is never caught by OnUnhandledException
in my bootstrapper. Neither is it caught by the Application.DispatcherUnhandledException
event handler.
How can I make a general exception handler that will also catch these types of exceptions, without having to implement try/catch everywhere?