views:

451

answers:

3

I recently wasted a lot of time trying to debug a WPF datagrid (from the WPF Toolkit). I had a column bound to a linq query with a property that was throwing an exception (in a few rows). WPF seems to catch the exception and it just makes the cells blank. I have fixed the bug causing the exception, but I would like to change WPF's behavior. I always want to know if something is wrong. Why is swallowing the exception the default behavior and how can I change it?

+5  A: 

Databinding errors are swallowed natively, but they are displayed in the OUTPUT dialog in the visual studio interface. If you wish to be notified (and have as much control over it as possible), then you can use Trace Sources.

Bea Stollnitz provides a great writeup about this (and debuginng the bindings in general) here: http://www.beacosta.com/blog/?p=52

Stephen Wrighton
+1  A: 

In case you would like to setup a validation for it, you can add ExceptionValidationRule

http://msdn.microsoft.com/en-us/library/system.windows.controls.exceptionvalidationrule.aspx

JoshKraker
A: 

Enabling First Chance Exceptions in the debugger (Debug -> Exceptions) will help with this as well, though it can get annoying

Paul Betts
Actually, that doesn't cause this variety of exception to break execution for some reason.
PeterAllenWebb
If not, you've done something wrong - this will definitely break execution, I've done it before.
Paul Betts