-1

In a porting from WinForm to WPF, I setted up a WindowsFormsHost that hosts all my old Form.

I'm setting the form as child in a setter like this:

set{
  try{
    windowsFormsHost.Child = value;
  }
  catch{}
}

Then, I noticed that if the Load function of the form (value in this case) throws an exception, the function just go further and I cannot see the exception. Even if I use a try catch block, nothing happens.

How can I catch the exceptions thrown by value load?

Emanuele
  • 723
  • 4
  • 15

1 Answers1

0

Setting the Child property won't cause an exception to be thrown.

It gets thrown at a later stage, long after your try/catch block has been executed and the method where this code is defined has already returned.

You need to catch exceptions where they occur, i.e. inside your form in this case.

You may also define global error handlers in your app.

mm8
  • 163,881
  • 10
  • 57
  • 88