I think you have your code in Form_Load
, as that would explain it. If this is the case, have a look at my question here: Explain critical bug in Visual Studio 2010 and up, WinForms and WPF. It is a known issue. You need to either put your code out of Form_Load
or make your application start from Sub Main
and put those 3 magic lines you already found for C#. Here are the same 3 lines for VB.NET:
AddHandler Application.ThreadException, AddressOf YourExceptionHandler
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf YourExceptionHandler
As far as I remember, the first line actually fixes this problem, the other 2 are to cover for other mysterious errors. It does not hurt to always include them all at the very start of your program, just to be safe. YourExceptionHandler
can be an empty method. Once you add these 3 lines, exception catching should start working as expected.