Error handling in functions
Guys,
I have a question about error handling in simple functions like the following:
Code:
Function fcnGetToken(str As String, strDelimiter As String, lngTokenNumber As Long) As String
'Function to return a token from a delimited string (1-based).
'E.g. fcnGetToken("14|Hello world!|123", "|", 2) = Hello world!
Dim strToken As String
'Ensure string has been supplied
Debug.Assert Len(str) > 0
'Ensure delimiter has been supplied
Debug.Assert Len(strDelimiter) > 0
'Ensure delimiter exists in string
Debug.Assert InStr(str, strDelimiter) <> 0
'Ensure lngTokenNumber exists in string
Debug.Assert (lngTokenNumber - 1) <= UBound(Split(str, strDelimiter))
strToken = Split(str, strDelimiter)(lngTokenNumber - 1) 'Split() is zero-based
fcnGetToken = strToken
lbl_Exit:
Exit Function
End Function
Say I have been using the Debug.Assert statements throughout testing to ensure that accepted values are being fed in, and everything seems fine. If for some reason after testing, when the .Assert statements are turned off, the function accepts a value which is unprepared for and will cause problems down the line - what should the course of action be?
Write an error log and stop execution?
Joe