We help IT Professionals succeed at work.
Get Started

VB.NET - Catch all Thread exceptions, even exceptions in newly created threads.

Last Modified: 2013-11-07
I was wondering if anyone knew how to catch global exceptions in a VB.NET windows form application. Here is what I have tried already:

AddHandler System.Windows.Forms.Application.ThreadException, AddressOf HandleException

This works great for exceptions thrown within the main form's thread.

However, if I do something like the following:

Sub TheThread()
    'code that causes exception.
End Sub

then inside my .net form app, I create a button that initiates the thread like so:

Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click

    Dim oThread as Threading.Thread = New Threading.Thread(AddressOf TheThread)

End Sub

the application will actually crash and exception will not get "Handled".


My Goal is to be able to output a memory dump of the exception causing the error on the main form thread and any thread being started by the form out to a file on the system for reporting later.

Thanks in advance for any assistance on this.
Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE