In the code below where I have the first catch will the return false staement result in the Finally block not getting called? Or does the Finally block get called regardless??
Visual Basic:
Public Function Save() As Boolean
Dim intX As Integer
' set internal error flag to false
m_Error = False
' if validatedata returns false the data cannot be saved, user must recify
If Not ValidateData() Then
Return False
End If
' if CalculateServiceDates returns false the data cannot be saved as service due dates are not created
If Not CalculateServiceDates() Then
Return False
End If
' create a new command builder object based on this supplier objects data
m_ocbContract = New System.Data.OleDb.OleDbCommandBuilder(m_odaContract)
' protect this section of code
Try
' signal beginning of edit
m_drContract.BeginEdit()
' write the private members to the corresponding data column
m_drContract.Item("pr_number") = m_PRNumber
m_drContract.Item("budget") = m_BudgetCode
m_drContract.Item("dept") = m_DepartmentCode
m_drContract.Item("po_number") = m_PONumber
m_drContract.Item("dated") = m_Dated
m_drContract.Item("Commencement") = m_Commencement
m_drContract.Item("expires") = m_Expiry
m_drContract.Item("contact") = m_Contact
m_drContract.Item("contact_tel") = m_ContactTelephone
m_drContract.Item("price") = m_Cost
m_drContract.Item("frequency") = m_Frequency
m_drContract.Item("order_line") = m_OrderLine
m_drContract.Item("description") = m_Detail
m_drContract.Item("internal") = m_Internal
' cycle through array and store service due dates in table
For intX = 0 To m_Frequency - 1
m_drContract.Item("s" & intX) = m_ServiceDates(intX, 0)
m_drContract.Item("s" & intX & "done") = m_ServiceDates(intX, 1)
Next
' signal end of edit
m_drContract.EndEdit()
' get the required update command for this data
m_odaContract.UpdateCommand = m_ocbContract.GetUpdateCommand
' update the table in the database checking for concurrency errors while we are at it
m_odaContract.Update(m_dsContract.Tables("tblContracts").GetChanges)
' signal to accept the changes
m_dsContract.Tables("tblContracts").AcceptChanges()
' close the connection
m_odaContract.UpdateCommand.Connection.Close()
Catch objConcurrencyError As DBConcurrencyException
ShowError("Location: Class Contract" & ControlChars.CrLf & ControlChars.CrLf & "Procedure: Save() As " & _
"Boolean" & ControlChars.CrLf & ControlChars.CrLf & "Error Text: " & "Another user has made " & _
"changes to this record since you opened it. You must " & ControlChars.CrLf & _
"reload the record and try again.")
' set internal error flag to true
m_Error = True
Return False
Catch objException As Exception
ShowError("Location: Class Contract" & ControlChars.CrLf & ControlChars.CrLf & _
"Procedure: Save() As Boolean" & ControlChars.CrLf & ControlChars.CrLf & _
"Error Text: " & objException.Message)
' set internal error flag to true
m_Error = True
Finally
If m_odaContract.UpdateCommand.Connection.State.Open Then
' close the connection
m_odaContract.UpdateCommand.Connection.Close()
End If
End Try
' return true to sigan data has been saved
Return True
End Function