Some extra notes for a few Posts
http://www.eileenslounge.com/viewtop...278892#p278892
https://www.myonlinetraininghub.com/...andling-in-vba
https://excelfox.com/forum/showthrea...GoRoT-N0Nula-1
https://excelfox.com/forum/showthrea...0559#post10559
_.... from last post
If we use On Error GoTo [LABEL] and then use Resume ( Resume; Resume Next; Resume [label] ) then we appear to be having something done very similar, or possibly exactly the same as On Error GoTo -1 , since the exception state is cleared and the Err object is cleared.
To demonstrate this we can do the last three routines again, and simply add another error handler , for example On Error Resume Next , after the return point, and follow this by an error. If the error is handled, that is to say we get no default VBA error message, then we know that the exception had been cleared previously. If it had not been cleared then the new error handler, On Error Resume Next , would have been ignored and we would have seen the default VBA error handler warning pop up message.
Code:' If we use On Error GoTo [LABEL] and then use Resume ( Resume; Resume Next; Resume [label] ) then we appear to be having something done very similar, or possibly exactly the same as On Error GoTo -1 , since the exception state is cleared and the Err object is cleared. Sub Resume_ClearsErr_() ' _ Resume, ( Resume ) Dim Rslt As Double, Demonostrator As Long On Error GoTo ErrHndler Debug.Print Err & vbCr & vbLf & Error Let Rslt = 1 / Demonostrator Debug.Print Err & vbCr & vbLf & Error On Error Resume Next ' This would be ignored if I was in exception state. Let Rslt = 1 / 0 ' This does not give us an error , so the last code line worked, indicating that we were not in exception state On Error GoTo 0 ' I do not need to do this since I am Exiting Sub in next code line. But it is good practice to get in the habit of doing this to return to normnal default VBA error handling if i know i am finished using the Error handler which I enabled Exit Sub ErrHndler: Debug.Print Err & vbCr & vbLf & Error Let Demonostrator = 1 Resume End Sub Sub Resume_Next_ClearsErr_() ' 'Resume, ( Resume Next ) Dim Rslt As Double On Error GoTo ErrHndler Debug.Print Err & vbCr & vbLf & Error Let Rslt = 1 / 0 Debug.Print Err & vbCr & vbLf & Error On Error Resume Next ' This would be ignored if I was in exception state. Let Rslt = 1 / 0 ' This does not give us an error , so the last code line worked, indicating that we were not in exception state On Error GoTo 0 ' I do not need to do this since I am Exiting Sub in next code line. But it is good practice to get in the habit of doing this to return to normnal default VBA error handling if i know i am finished using the Error handler which I enabled Exit Sub ErrHndler: Debug.Print Err & vbCr & vbLf & Error Resume Next End Sub Sub Resume_LABEL_ClearsErr_() ' 'Resume, ( Resume [label] ) Dim Rslt As Double On Error GoTo ErrHndler Debug.Print Err & vbCr & vbLf & Error Let Rslt = 1 / 0 Lbl: Debug.Print Err & vbCr & vbLf & Error On Error Resume Next ' This would be ignored if I was in exception state. Let Rslt = 1 / 0 ' This does not give us an error , so the last code line worked, indicating that we were not in exception state On Error GoTo 0 ' I do not need to do this since I am Exiting Sub in next code line. But it is good practice to get in the habit of doing this to return to normnal default VBA error handling if i know i am finished using the Error handler which I enabled Exit Sub ErrHndler: Debug.Print Err & vbCr & vbLf & Error Resume Lbl End Sub




Reply With Quote
Bookmarks