Test Design StudioGo to Previous Topic: CA0119 - Avoid addition operator for string concatenationGo to Next Topic: CA0122 - Restore recovery when disabled in routines

CA0120 - Close error handlers in routines

Summary

It is often necessary to use the 'On Error Resume Next' statement to prevent errors from interrupting the execution of code. When used within a procedure, it is important to turn error handling back on before you leave the routine or else other code may not execute correctly.

Note:    This rule can only check for the presence of the 'On Error Goto 0' statement, but cannot analyze the execution flow of your routine to make sure it is called before every possible exit path. If you have multiple exit paths (via 'Exit Function', 'Exit Sub', or 'Exit Property'), make sure that 'On Error Goto 0' is called before each exit as well as at the end of the routine.

Solution

Add the statement 'On Error Goto 0' before every exit path of the routine.