Caution: Opinionated opinion ahead!
The reality is even a bit goofier than already described.
For example [tt]Option Explicit[/tt] is partially compile time, partially run time.
This and the reasons behind it can be found at
Let's Get Explicit!. This guy wrote much of the code in the Microsoft Script Engines, so he ought to know.
The basic idea is that you can destroy the full value of [tt]Option Explicit[/tt] by setting [tt]On Error Resume Next[/tt] globally.
But a script should
never be written with [tt]On Error Resume Next[/tt] at the head (and at the head of every procedure - Sub or Function). There isn't any legitimacy to this. What would it buy you?
Basically you are telling the Script Engine "ignore any exception, just try to keep on running the code."
In reality, in VBScript you use [tt]On Error[/tt] to implement a "try/catch" mechanism for errors you want to handle in your code instead of just having the script blow up.
Example:
Code:
:
On Error Resume Next
objRS.Open strSQL, strCon1, adOpenForwardOnly
If Err.Number <> 0 Then
On Error GoTo 0
objRS.Open strSQL, strCon2, adOpenForwardOnly
End If
On Error GoTo 0
:
This contrived example tries to open a recordset to one server defined by the ADO connection string contained in strCon1, and if it fails then it tries to open the recordset to another server as defined in strCon2.
In other words, the script
has a reason to trap the exception.
Note that once the operation we want to trap exceptions on has completed (or failed) we shut off error trapping. That's because we want any further exceptions in the script (including a failure to connect the second time) to abort the script and inform the user.
I welcome alternative opinions, I'm always glad to learn something new.