Page 1 of 1 1
Topic Options
#80810 - 2002-05-10 08:03 PM on error
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
something like :

onerror("exit @error")
$objConn = CreateObject("ADODB.Connection")
$objConn.ConnectionTimeout = $ConnTimeout
$objConn.Open($ConnDSN)
endonerror

instead of

$objConn = CreateObject("ADODB.Connection") if @ERROR exit @ERROR endif
$objConn.ConnectionTimeout = $ConnTimeout if @ERROR exit @ERROR endif
$objConn.CommandTimeout = $CmdTimeout if @ERROR exit @ERROR endif
$objConn.Open($ConnDSN) if @ERROR exit @ERROR endif

[ 10 May 2002, 20:06: Message edited by: Radimus ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#80811 - 2002-05-20 11:54 PM Re: on error
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear Radimus,

A good idea. In some other languages we have such capability.
It will reduce the requirement of additional code for abnormal
situations. Specially when scripts aborts.

Our suggestion is to extend your OnError function
with the capability to execute a piece of kixtart script
f.e.
  • OnError(exit @error)
  • OnError(MessageBox("Script abort with error @error (@serror)","KiXtart @scriptname"))
  • $message='MessageBox("Script abort with error @error (@serror)","KiXtart @scriptname")'
    OnError(Execute($message) Exit @error)
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#80812 - 2002-05-21 03:25 PM Re: on error
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
that is exactly what I meant...
[Big Grin]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#80813 - 2002-05-21 03:37 PM Re: on error
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
This came up a little while ago...

Here it is: On Error handler?

Top
#80814 - 2003-05-29 09:58 PM Re: on error
JensKalski Offline
Starting to like KiXtart

Registered: 2000-12-13
Posts: 186
Loc: Germany
I need it too!
_________________________
Jens Kalski

Top
#80815 - 2003-05-29 10:30 PM Re: on error
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
I still must wonder, what for one would like this?

a way to check if his script crashes?
thus, lack of proper coding?
_________________________
!

download KiXnet

Top
#80816 - 2003-05-29 10:35 PM Re: on error
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Because you might want to trap certain errors that can happen within a block of code due to circumstances out of control of the script itself. Just take a look at Radimus' example. Instead of checking the error code of each COM-function, you can group them together and achive a lower KiXgolf score.
_________________________
There are two types of vessels, submarines and targets.

Top
#80817 - 2003-05-30 12:18 AM Re: on error
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
I know what you mean but if you look at the code rad provided, you see this:
$objConn = CreateObject("ADODB.Connection")

you may get error if system does not have this functionality.
and:
$objConn.ConnectionTimeout = $ConnTimeout
$objConn.Open($ConnDSN)

these are dependant of the first one.
if you don't know if the system has services of the needed type, you just want kixtart to take the errors for you?
it's just sloppy code, nothing else.
there is no reason why any soft or com call would return any error if not specifically needed.

and needs are of 2 types:
-1 = coder writes code that is unsupported
-2 = end user makes a choise that causes error

these are both predictable.
thus, I don't see any reason for on-error "event"
_________________________
!

download KiXnet

Top
#80818 - 2003-06-01 07:15 PM Re: on error
JensKalski Offline
Starting to like KiXtart

Registered: 2000-12-13
Posts: 186
Loc: Germany
I have tried to write a Kix-Script to check websites in our Intranet and at the internet. For this I'm using the "WinHttp.WinHttpRequest.5.1"-object. There I can set the proxy and first of all a timeout. But when I check the websites and a timeout occurs, the Kixtart-Script Quits.

In vbscript I can change this behaviour and check the error-object after the check times out.

For using all of the nice COM-Objects it absolutely neccesary that we have a thing like ON ERROR RESUME NEXT. For the webcheck-script I had to change to vbscript [Frown]
_________________________
Jens Kalski

Top
#80819 - 2003-06-01 08:14 PM Re: on error
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
again, your script quits because you don't have a check for the objects results.
little better code will remove the need for this.

also, you don't neccessarely need the winhhtp-object as with ie5 and later you can use xmlhttp-object which ships with ie (although it uses the same settings as ie).
_________________________
!

download KiXnet

Top
#80820 - 2003-06-05 09:47 AM Re: on error
JensKalski Offline
Starting to like KiXtart

Registered: 2000-12-13
Posts: 186
Loc: Germany
Here is a little sample

code:
BREAK ON
$ = SETOPTION("Explicit", "ON")

GLOBAL $False
$False = (0=1)
DIM $Status

GLOBAL $HTTPRequest
$HTTPRequest = CreateObject("winhttp.winhttprequest.5.1")
IF @ERROR <> 0
$ = Log("CreateObject [winhttp.winhttprequest.5.1] failed!")
QUIT
ENDIF

$Status = CheckURL("http://www.microsoft.com/")
? "http://www.microsoft.com/" + " --- " + $Status

$Status = CheckURL("http://infoportal.gv.hamburg.de/infoportal")
? "http://infoportal.gv.hamburg.de/infoportal" + " --- " + $Status

$Status = CheckURL("http://www.microsoft.com/")
? "http://www.microsoft.com/" + " --- " + $Status

EXIT 0

;------------------------------------------------------------------------------

FUNCTION CheckURL($URL)
$HTTPRequest.SetProxy(2, "proxy.gv.hamburg.de", "<localhost>;")
$HTTPRequest.SetTimeouts(2000, 2000, 2000, 2000)
$ = $HTTPRequest.Open("GET", $URL, $False)
$ = $HTTPRequest.Send
; Here the script dies when it timeout
$CheckURL = $HTTPRequest.Status
ENDFUNCTION

The Script dies after the .Send when it times out. How can this be catched with kix?
_________________________
Jens Kalski

Top
#80821 - 2003-06-05 09:59 AM Re: on error
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
dunno why it does that for you as it does not do that for me.
but what it does is give error 9 of the status line.
com objects have 2 most usual errors: 6 and 9.
they mostlikely mean: "this da thing is not supported"

but indeed, it does not crash for me, it just returns nothing [Big Grin]
_________________________
!

download KiXnet

Top
#80822 - 2003-06-05 10:58 AM Re: on error
JensKalski Offline
Starting to like KiXtart

Registered: 2000-12-13
Posts: 186
Loc: Germany
Maybe it's a Kix-Bug.
_________________________
Jens Kalski

Top
#80823 - 2003-06-05 11:30 AM Re: on error
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
it's good to quess so.
I think it's bug in your OS.

you have no lead what so ever what the problem is.
and like your example has shown, onerror is not needed but more proper script control.

basically com already is higher level scripting so it also requires more carefull coding.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 142 anonymous users online.
Newest Members
KatieQuinn, Brennnnn, MKubicsek, xguixa, mdress
17681 Registered Users

Generated in 0.079 seconds in which 0.053 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org