views:

52

answers:

2

I have a single-threaded IronPython WPF application and if an event handler (FrameworkElement.SizeChanged for example) throws, the exception is just eaten and execution continues without any kind of notification.

Because of this I spent a lot of time today solving an "impossible" bug.

Does the same thing happen when using WPF from C#? What happens there if SizeChanged throws?

And is there a way to globally catch exceptions thrown by event handlers, but which don't terminate the application?

A: 

If you're just interested in this while debugging than check "Thrown" in "Common Language Runtime Exceptions" from Debug - Exceptions in Visual Studio. Then the debugger will stop everytime an exception occured.

And if you're interested in the .NET Framework source as well then you can load the symbols for most of it by checking "Microsoft Symbol Servers" from Tools - Options - Debugging - Symbols and "Enable .NET Framework source stepping" from Tools - Options - Debugging - General.

This doesn't just stop on the exceptions thrown by event handlers but hopefully it'll be helpfull.

Meleak
A: 

A useful trick in c# for catching exceptions globally, is to wrap the entry point for your program in a try-catch block. Any unhandled exceptions will wind their way up to it. Depending on the nature of the exception, it may stop the program from terminating.

EDIT

Thought this might also be relevant to your interests.

http://stackoverflow.com/questions/1472498/wpf-global-exception-handler

Val