How can I terminate console application in Try…Catch…F inally…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.WriteLi ne(i(3).ToStrin g)
Catch ex As Exception
Console.WriteLi ne(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.WriteLi ne(i(1).ToStrin g)
Catch ex As Exception
Console.WriteLi ne(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.WriteLi ne(i(3).ToStrin g)
Catch ex As Exception
Console.WriteLi ne(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.WriteLi ne(i(1).ToStrin g)
Catch ex As Exception
Console.WriteLi ne(ex.Message)
Finally
i = Nothing
End Try
End Sub
End Module
Comment