Weird unhandled exception with WPF
I have a WPF application with which I ask the user some settings to connect to a database, than I connect to the database (using NHibernate) and if everything is right I show my main view. If there is an error in the connection, I'd like to tell the user what is the error and let him retry. Here is some simplified code doing what I want:
EDIT :
It seems the problem isn't only with NHibernate. If I just run the simple app here, I get unhandled exception in the constructor.
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
bool retry;
do
{
retry = false;
Window1 view = new Window1();
try
{
throw new Exception("Test message");
view.ShowDialog();
}
catch (Exception iException)
{
MessageBox.Show(iException.ToString());
retry = true;
}
finally
{
view.Close();
}
}
while (retry);
}
}
I do get and unhandled exception and it gives me my test message so it really is my exception (even if it is inside a try/catch block). If I break when I get the exception it tells me it happens inside the constructor of Window1. Window1 doesn't contain any binding or control. It is just the basic Window1 that gets created if you create a new WPF Application in visual studio 2008. I have reproduced this bug on 2 computers (just create a new WPF application and paste this code in App.xaml.cs)
Thank you for your help everyone
I solved the problem by creating the window only once (before the loop). Than instead of closing it in the finally block I call Hide, and I close it only after the loop.
There could be any number of exceptions that could be happening and without posting the exception details, it's pretty hard to diagnose.
If I were to guess, my guess would be that view.Close() is throwing, since you say it's not being caught.
Try calling session.clear() in your catch statement.
Nhibernate will continue to buffer SQL until it writes to the database (flush). If you have a problem (exception), it won't throw it at the point when the exception occurs, but rather when the session gets flushed (when it tries to write the SQL to the DB).
Post the NHibernate exception, I could be way off on this..
链接地址: http://www.djcxy.com/p/51232.html下一篇: 奇怪的未经处理的WPF异常