VB.net Program to Demonstrate the Finally Block In Exception Handling

You are currently viewing VB.net Program to Demonstrate the Finally Block In Exception Handling

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 . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply