This will catch any exception that you do not explicitly handle. Not only can you gather information about the state of the application when the exception is thrown, but it also gives you a chance to shut down the app cleanly.

VB Code:
  1. Imports System.Threading
  2.  
  3. Public Class frmMain
  4.     Inherits System.Windows.Forms.Form
  5.  
  6.     '//Windows Form Designer generated code
  7.  
  8.     Public Shared Sub Main()
  9.         Dim frm As New frmMain
  10.  
  11.         'Install a ThreadException Handler
  12.         AddHandler Application.ThreadException, _
  13.                    New ThreadExceptionEventHandler(AddressOf frm.GlobalErrorProc)
  14.  
  15.         'Run the main form
  16.         Application.Run(frm)
  17.  
  18.     End Sub
  19.  
  20.     Public Sub GlobalErrorProc(ByVal sender As Object, _
  21.                                ByVal args As ThreadExceptionEventArgs)
  22.  
  23.         'Inform the user of the exception, and allow the application to close nicely
  24.         MessageBox.Show("An unhandled exception has occured: " & args.Exception.Message, _
  25.                         "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
  26.         Me.Close()
  27.         Application.Exit()
  28.  
  29.         'You could also write the stack trace out to a file or something at this for
  30.         'debugging purposes, or gather any other state info that you want
  31.  
  32.     End Sub
  33.  
  34.     Private Sub Button1_Click(ByVal sender As Object, _
  35.                               ByVal e As System.EventArgs) Handles Button1.Click
  36.         'Just to test it out, throw an exception
  37.         Throw New Exception("This is a test")
  38.     End Sub
  39.  
  40. End Class