Login | |
|
 |
RE: About err.raise - 5/12/2006 5:28:45 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
|
If you just want the script to terminate with a non-zero exit code, use this: WScript.Quit(1) This would exit with an exit code of 1. You can of course us whatever integer suits your fancy.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: About err.raise - 5/12/2006 5:49:33 AM
|
|
 |
|
| |
ehvbs
Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
|
Hi SpankyATL, I don't even know, what CA7 is, so this may be wrong: To raise an error, you should do something like that: If <SQL failure> Then ' object.Raise number, source, description [, helpfile, helpcontext ] Err.Raise vbObjectError + <YourNumber>, "SQL job check", "the details: ...." End If What happens after that depends on the process/program that hosts your script (cscript.exe will terminate the script and print a message, IE will show a dialog; I don't know, how your CA7 agent will react). If the CA7 agent starts your script by shelling out and using cscript.exe to run it, then If <SQL failure> Then WScript.Quit 1 ' or some other number > 0 and < 256 End If would be a way to return an error code to DOS and the agent. If the CA7 agent loads your code and calls a function with a specific name you have to provide then you should do something like that: Function WorkForAgent( Whatever ) Dim nRVal : nRVal = 0 If <SQL failure> Then nRVal = 1 ' or some other number > 0 and < 256 End If WorkForAgent = nRVal End Function Isn't there some kind of documentation for this mysterious agent?
|
|
| |
|
|
|
 |
RE: About err.raise - 5/12/2006 6:05:40 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
|
I would like to make some comments. First Err.Raise will only cause the script to exit if error handling is turned on (On Error Goto 0) if error handling is off (On Error Resume Next) then Err.Raise will not cause the script to exit. Second, even if Err.Raise causes the script to exit, the exit code will be 0. To test this, write a script that has this one line in it: Err.Raise 1666, "FOO" Then run the script froma command line like this: CScript.exe Foo.vbs You will see this error message C:\Path\to\script\Foo.vbs(3, 1) FOO: Unknown runtime error Note that this error message is not the exit code. The exit code is given by doing this at the command line: Echo %errorlevel% You will see that the exit code is 0. Not 1666. To test that WScript.Quit does produce the proper exit code, make a vbscript with this line in it: WScript.Quit(1666) Run it at the command line with: CScript.exe foo.vbs Then do: Echo %errorlevel% and you will see that the exit code for the script was 1666. This brings me to my third point that exit codes are not limited to 0-256.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|