Catch All Unhandled Exceptions : Catch Exception « Language Basics « VB.Net






Catch All Unhandled Exceptions

Catch All Unhandled Exceptions
Imports System
Imports System.Windows.Forms
Imports System.IO

Public Class MainClass

   Shared Sub Main()
        AddHandler Application.ThreadException, AddressOf app_ThreadException

        Application.OnThreadException(New InvalidDataException("There"))

        Throw New InvalidDataException("Here")


   End Sub 

   ' Catch a ThreadException event.
    Shared Private Sub app_ThreadException(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)
        Console.WriteLine("Caught unhandled exception")
    End Sub

End Class

           
       








Related examples in the same category

1.Catch Exception DemoCatch Exception Demo
2.Try and catch Exception: InvalidCastException