|
Guy recommends :
Find out which of your VMs are a waste of space and which VMs need more resources.
|
VBScript - Error HandlingIntroduction to Error Handling'Best Practice' dictates that we should take steps to control errors. Another reason for error handling is that it saves time troubleshooting when you can narrow down the problem to one section of the script. In practice you have three, choices, write a statement that says ignore errors and carry on processing, allow errors to surface naturally, or add error handling statements (best), which will give you valuable information on where in the script the error is arising. On Error Resume NextWhat the 'On Error Resume Next' statement does is defer error handling, and suppress a system message. The script will carry on running but you may be storing up problems. There is counter statement called 'On Error GoTo 0' which turns off 'On Error Resume Next'. This means that you can have different error handling for different sections of you script. On Error Resume Next
Note 1: Without an 'On Error Resume Next' command, any run-time error will result in pop-up message box with an error message and the code will execute no further than the error. Clear Method - err.ClearUse the Clear method to explicitly reset the Err object once an error has been handled. When you use deferred error handling with On Error Resume Next, you reset the err.raise to zero with a statement err.Clear. Note 1: VBScript calls the Clear method whenever you Exit a Sub or Exit a function. Example of error handlingIf Err.Number <> 0 Then
Note 1: This error handling routine uses the If ... Then ... End If construction. Note 2: Here is a classic use of the Wscript.Echo method. The & strOUContainer is a neat touch to let you know in the message box exactly what is wrong with LDAP path. Note 3: If you actually see this error it means you need to find the variable strOUContainer and change the value to your domain. Note 4: These error handling statements occur all through the script, each with an appropriate message. The fact that VBScript is an interpreted language rather than a compiled language means that you can expect more runtime errors. To trap these bugs you need to build in error handling statements which pinpoint coding errors such spelling mistakes in variables.
Guy
Recommends: Permissions Analyzer - Free Active Directory Tool
|
||||
Custom Search
|
Guy Recommends: WMI Monitor and It's Free!
|
|
Home Copyright © 1999-2012 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |