I am new to WPF, I am using VS2010 beta2, .NET 4.0.
Throw new Exception("test") in my code just swallows an exception and the application is not crashing.
This is not what I expect, I want the application to crash if an unhandled exception occurs.
Is there an easy way to achieve this?
Also it is not satisfied Application.DispatcherUnhandledException, no AppDomain.UnhandledException. Probably because all the code is executed as part of the data binding (I use the MVVM template, and the exception is thrown in the ViewModel constructor).
During debugging, I can look at the output window and find out what is wrong. But it seems strange to me that the application simply ignores the error, leaves the user interface in the wrong state and does not crash.
Edit:
It seems that perhaps only non-critical binding exceptions may occur during the data binding process. Perhaps a solution to the problem associated with the binding (for example, connecting to the database) directly from the execution of the binding may be a solution. However, I am not sure how to achieve this in MVVM.
A simplified example:
XAML:
<DataTemplate DataType="{x:Type vm:ItemViewModel}">
<vw:ItemControl />
</DataTemplate>
<ContentControl
Content="{Binding Path=MyItem}"
/>
where MyItemcreates and returns an instance ItemViewModel. The problem is that the constructor ItemViewModelis executed as part of the data binding, and I'm not sure if this is good practice (this constructor contains code that may fail, for example, if the database is not available).
source
share