Confusing?? Just see the code below
Public Sub MyFun()
Try Dim ope = 2Dim a As Integer = 10 / ope
Catch ex As Exception
MessageBox.Show("Exception") Return Finally MessageBox.Show("Finally")End Try
End SubPublic Sub MyFun()
Try Dim ope = 0Dim a As Integer = 10 / ope
Catch ex As Exception
MessageBox.Show("Exception") Return Finally MessageBox.Show("Finally")End Try
End SubThere is no question that the above code will throw an exception.Then the catch will get executed which contains a return statement.Will that return statement works properly and go back to the calling function?
The answer is NO. The finally will execute even the catch contains a return.

No comments:
Post a Comment