Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will statements or expressions execute after a return statement in VB.net?

Tags:

vb.net

Ok, I was rooting around in one of our company apps which is done in VB.net. I'm not familiar with VB.net (I do stuff in C#) so I'm asking this question: Does the code after the clean up comment execute?

Public Function DoesUserHavePermission(ByVal UserID As Integer, ByVal ActionID As Integer) As Boolean
    ' some extra code re: getting data


     Return UserHasPermission

     '-Clean Up-
     MySqlCommand.Dispose()
     MySqlConnection.Dispose()
     RowCount = Nothing


End Function

It is my understanding once you say return, you give the calling function control again. Is this a VB.Net oddity which I have to accept or a giant WTF?

like image 455
KeithA Avatar asked Dec 22 '22 06:12

KeithA


1 Answers

The statements after the Clean up comment will not execute. This is a candidate for enclosure within Try/Catch/Finally.

like image 140
Ta01 Avatar answered Jun 05 '23 18:06

Ta01