Our goal is to create defensive code that protects the user against the most common logon script problems. Let us start with a simple strategy. We are going to tell the script not to give up, but to ignore the error and carry on with the next instruction. The VBScript command to achieve our goal is : On Error Resume Next.
I've done a ton of vbScript (most of my apps at work from 2000-2008 were glue, data mining and system maintenance apps) and I used ON ERROR RESUME NEXT a lot. Most of my apps ran unattended and it was not acceptable for them to abort. However, I would not recommend it for VB apps. This may be against the general concensus but my recommendation is to use code to test for possible errors prior to doing an operation where possible and use TRY-CATCH sparingly. For example, if you are planning to do a numeric operation on the contents of a textbox, my preference would be to do something like
You can say: On Error Resume Next.
My recommendation is to get rid of On Error Resume Next, and always use
timeTry/Catch in the appropriate places. Usually if an unexpected run
error ocurred, you don't want to execute any more statements - so Ineverreally understood why you would want to Resume Next. If an errorhappensthat you were not expecting, you need to handle it, and get out
The "On Error Goto [label]" syntax is supported by Visual Basic and Visual Basic for Applications (VBA), but VBScript doesn't support this language feature so you have to use On Error Resume Next as described above.On Error Resume Next causes execution to continue with the statement immediately following the statement that caused the run-time error, or with the statement immediately following the most recent call out of the procedure containing the On Error Resume Next statement. This statement allows execution to continue despite a run-time error. You can place the error-handling routine where the error would occur, rather than transferring control to another location within the procedure. An On Error Resume Next statement becomes inactive when another procedure is called, so you should execute an On Error Resume Next statement in each called routine if you want inline error handling within that routine.