VB.Net program to demonstrate the finally block in exception handling
'Vb.Net program to demonstrate the finally block.
Module Module1
Class Sample
Public Sub SayHello()
Console.WriteLine("Hello World")
End Sub
End Class
Sub Main()
Try
Dim S As New Sample()
S = Nothing
S.SayHello()
Catch e As NullReferenceException
Console.WriteLine(e.Message)
Finally
Console.WriteLine("Finally block gets executed")
End Try
End Sub
End Module
Object reference not set to an instance of an object.
Finally block gets executed
Press any key to continue . . .
Table of Contents