If the "Application Frame" is enabled in the project properties, click the "View Applications" button on the "Application" project properties page. Then add an event handler:
Partial Friend Class MyApplication Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException ' ... End Sub End Class
If you are not using the application framework, you should place a catch try block around your Main
method. However, this will only lead to exceptions that occur in the main thread. If your application is multi-threaded, you can handle exceptions from all threads by creating this method:
Public Sub UnhandledExceptionHandler(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs) ' ... End Sub
And then attach it to the current UnhandledException
domain, for example:
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionHandler
This event handler will be called for all unhandled exceptions from anywhere in your domain, regardless of the current thread.
source share