Reputation: 5199
Try
xConn.ConnectionString = xConnBuilder.ConnectionString
xConn.Open()
Throw New Exception("Something")
Catch ex As Exception
Throw
Finally
If xConn.State = ConnectionState.Open Then
xConn.Close()
End If
End Try
What happens to the connection object after the exception is thrown and re-thrown maintaining the stack trace, is it closed, because the finally block is not reached in case of exception.
Upvotes: 0
Views: 97
Reputation: 11
In your sample code the connection will be closed. The finally code block is always executed irrespective of exception occurs or not.
Upvotes: 1
Reputation: 22323
Finally block contains the code that must be executed no matter weather there was an error/exception or not.
Upvotes: 3