Radimus
(KiX Supporter)
2002-05-10 08:03 PM
on error

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 ]


MCA
(KiX Supporter)
2002-05-20 11:54 PM
Re: on error

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.


Radimus
(KiX Supporter)
2002-05-21 03:25 PM
Re: on error

that is exactly what I meant...
[Big Grin]


Richard H.Administrator
(KiX Supporter)
2002-05-21 03:37 PM
Re: on error

This came up a little while ago...

Here it is: On Error handler?


JensKalski
(Starting to like KiXtart)
2003-05-29 09:58 PM
Re: on error

I need it too!

LonkeroAdministrator
(KiX Master Guru)
2003-05-29 10:30 PM
Re: on error

I still must wonder, what for one would like this?

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


Sealeopard
(KiX Master)
2003-05-29 10:35 PM
Re: on error

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.

LonkeroAdministrator
(KiX Master Guru)
2003-05-30 12:18 AM
Re: on error

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"


JensKalski
(Starting to like KiXtart)
2003-06-01 07:15 PM
Re: on error

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]


LonkeroAdministrator
(KiX Master Guru)
2003-06-01 08:14 PM
Re: on error

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


JensKalski
(Starting to like KiXtart)
2003-06-05 09:47 AM
Re: on error

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?


LonkeroAdministrator
(KiX Master Guru)
2003-06-05 09:59 AM
Re: on error

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]


JensKalski
(Starting to like KiXtart)
2003-06-05 10:58 AM
Re: on error

Maybe it's a Kix-Bug.

LonkeroAdministrator
(KiX Master Guru)
2003-06-05 11:30 AM
Re: on error

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.