G
Guest
How can I terminate console application in Try…Catch…Finally…End Try block so
that code in Finally gets executed. If I use End statement Finally does not
get executed.
Following is my code written in Console Application.
Module Module1
Sub Main()
Call Testing()
Call Testing2()
End Sub
Private Sub Testing()
Dim i() As Integer = {1, 2, 3}
Try
‘This will cause exception
Console.WriteLine(i(3).ToString)
Catch ex As Exception
Console.WriteLine(ex.Message)
‘I WANT CONSOLE TO BE TERMINATED HERE SO THAT FINALLY GET EXECUTED. IF I USE
END STATEMENT HERE FINALLY DOES NOT GET EXECUTED.
Finally
i = Nothing
End Try
End Sub
Private Sub Testing2()
Dim i() As Integer = {1, 2, 3}
Try
Console.WriteLine(i(1).ToString)
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
i = Nothing
End Try
End Sub
End Module
that code in Finally gets executed. If I use End statement Finally does not
get executed.
Following is my code written in Console Application.
Module Module1
Sub Main()
Call Testing()
Call Testing2()
End Sub
Private Sub Testing()
Dim i() As Integer = {1, 2, 3}
Try
‘This will cause exception
Console.WriteLine(i(3).ToString)
Catch ex As Exception
Console.WriteLine(ex.Message)
‘I WANT CONSOLE TO BE TERMINATED HERE SO THAT FINALLY GET EXECUTED. IF I USE
END STATEMENT HERE FINALLY DOES NOT GET EXECUTED.
Finally
i = Nothing
End Try
End Sub
Private Sub Testing2()
Dim i() As Integer = {1, 2, 3}
Try
Console.WriteLine(i(1).ToString)
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
i = Nothing
End Try
End Sub
End Module