Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50061

Is this a good way to handle error?

$
0
0
Code:

Private Function F1() As String

    On Error GoTo errHandler
   
    Open "c:\pfms.txt" For Input As #1

exitHere:
   
    Exit Function
   
errHandler:
    MsgBox "Error " & Err.Number
    Select Case Err
   
        Case 53 ' unrecoverable error
            Err.Raise 1, "F1"
            Exit Function
           
    End Select
   
End Function

I have a function called F1 and it has an error handler that handles err 53 (file not found err). When err 53 occurs, the error handler raises an an err 1 to exit the function. The function that calls F1 also has an error handler and the error handler reacts to the err 1 raised by the function F1.

Is it a good programming practice to notify the function caller that an error has occurred in the called function by using the err.raise method?

Viewing all articles
Browse latest Browse all 50061

Trending Articles