Or, since this is VB, you can use the built-in functionality for a global exception handler:
1. Double-click on My Project in a windows forms VB project.
2. Click on the Application tab.
3. Click on theView Application Events button.
4. Select MyApplication Events from the left drop-down.
5) Select UnhandledException from the right drop-down.
6) Add any desired code. Something like this will work:
Private Sub MyApplication_UnhandledException( _
ByVal sender As Object, _
ByVal e As Microsoft.VisualBasic.ApplicationServices. _
UnhandledExceptionEventArgs) _
Handles Me.UnhandledException
' Add logging here
' And display a message to the user
MessageBox.Show("The application could not process your request so it is shutting down. Please see your administrator")
End Sub
Hope this helps.
www.insteptech.com