Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


About err.raise

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,34424
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> About err.raise
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 About err.raise - 5/12/2006 5:16:46 AM   
  SpankyATL

 

Posts: 7
Score: 0
Joined: 5/9/2006
Status: offline
This is related to my SQL Monitoring script.  This script starts a sql job and then monitors it's status.  This script is being called by a CA7 Agent. 

If my script sees that the sql job has failed I don't want my script to end cleanly because CA7 will process whatever comes next.  The CA7 guy I spoke with speaks mainframe and not client-server and I don't speak mainframe so basically he said that if my script's return code is 0 then he would not know anything is wrong.  I'm thinking that if I raise an error in the script, that should cause the CA7 agent to error and then notifications would go out.

Am I on the right track here?  If so, what error should I raise?  If not, what should I do to make my script error out?

Sorry if this is basic stuff.  My only knowledge of VBScript is using it in SQL Server DTS packages which are simple to make return an error.
 
 
Post #: 1
 
 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

(in reply to SpankyATL)
 
 
Post #: 2
 
 RE: About err.raise - 5/12/2006 5:35:06 AM   
  SpankyATL

 

Posts: 7
Score: 0
Joined: 5/9/2006
Status: offline
Ok, so that assumes that CA7 would be using wscipt and not cscript...how should I tell the guy from CA7 to execute my script?  I was thinking it would be just the vbs filename.

quote:

ORIGINAL: ebgreen

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.

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: About err.raise - 5/12/2006 5:41:41 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
It doesn't matter if you are using WScript or CScript. The code I gave will give whatever exit code you want.

_____________________________

"... 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

(in reply to SpankyATL)
 
 
Post #: 4
 
 RE: About err.raise - 5/12/2006 5:46:00 AM   
  SpankyATL

 

Posts: 7
Score: 0
Joined: 5/9/2006
Status: offline
Thanks!

(in reply to ebgreen)
 
 
Post #: 5
 
 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?
 

(in reply to SpankyATL)
 
 
Post #: 6
 
 RE: About err.raise - 5/12/2006 6:05:01 AM   
  SpankyATL

 

Posts: 7
Score: 0
Joined: 5/9/2006
Status: offline
I don't have any documentation on it.  CA7 is a very popular scheduling tool from Computer Associates.  It's mainframe-based.  However it does have an agent that can run on intel-based systems. 

Here's a description of it:  http://www3.ca.com/solutions/Overview.aspx?ID=1021

I'm pretty sure the wscript.quit(1) statement will do the trick.

(in reply to ehvbs)
 
 
Post #: 7
 
 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

(in reply to ehvbs)
 
 
Post #: 8
 
 RE: About err.raise - 5/12/2006 6:27:23 AM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi ebgreen,

thanks for the clarifications. All points taken. I especially like your
addition of the tests/checks.

As this topic kind of grows to a more general discussion of error/return
level, I'd like to add one remark too:

Contrary to the VBScript Docs it should be

  WScript.Quit <Number>

Not

  WScript.Quit ( <Number> )

because you don't call a function and you don't need/want to 'constantify'
the number.

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: About err.raise - 5/12/2006 6:30:05 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Good point about calling WScript.Quit.

_____________________________

"... 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

(in reply to ehvbs)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> About err.raise Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts