views:

215

answers:

0

It appears that ShowDialog() invokes the Dispatcher message handling loop within. Thus, you have a stack that looks something like:

Outer-most Dispatcher message loop
...
x.ShowDialog()
Inner Dispatcher message loop
...

I am using the Dispatcher.UnhandledException to catch exceptions not handled by my code. However, it appears that the Inner Dispatcher message loop, above, is undesirably catching exceptions that my code would catch. Example:

Outer-most Dispatcher message loop
try/catch FooException
...
x.ShowDialog()
Inner Dispatcher message loop
...
throw FooException

What I would like is for the thrown FooException to get caught by the try/catch. However. It gets caught first by the (inner) Dispatcher.UnhandledException.

I see there are ways to filter the exception. However, those filters will apply to both the inner and outer most handlers. What I am looking for is to have my Dispatcher.UnhandledException code run only on the outer-most dispatcher message loop. Does that make sense?

I could, of course, reflect the call stack from within my handler to see if this is the outer-most dispatcher, but that seems a bit fragile. Other ideas?

Thanks!

Eric