Page 1 of 1 1
Topic Options
#113014 - 2004-02-02 05:10 AM "On Error" function or sub
Gaven Offline
Starting to like KiXtart
*

Registered: 2003-06-19
Posts: 103
Loc: Washinton DC, USA
Considering how easy it would be to add to KiXtart, I suggest those who write KiXtart allow for an "OnError" function with macros @ErrorLine and @Error energized with the line number and error code which triggered the program error. To clarify, the errors I refer to are those which cause the KiXtart program to terminate with an error code, not errors returned to a functioning script by something like, Open().
Top
#113015 - 2004-02-02 05:16 AM Re: "On Error" function or sub
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja, asked pretty many times before.
and raised depate is this for sloppy coders or is there really need for something like this.

I bet the first one.
_________________________
!

download KiXnet

Top
#113016 - 2004-02-02 05:47 AM Re: "On Error" function or sub
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Agreed - this is a sign of bad coding. You should be able to sort this out using one or both methods: (1) KiXStrip, and (2) W/KIX32.EXE itself.

Couple of other thoughts -
Optimization - Sure, Lonk or an expert at coding, but you need to think of what you are trying to achieve? Are you doing enough, or over-doing it? Too many of us, myself included can do the same thing with less.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#113017 - 2004-02-02 10:33 AM Re: "On Error" function or sub
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Agreed - this is a sign of bad coding




No, it's not.

It can of course be abused to produce poor or lazy coding, but it can also be used in a constructive manner as an exception trap.

I would much rather have a generic exception trap to email me when a login script abends for an unforseen reason than have the user whining that he hasn't had mapped drives/printers for 6 weeks and hasn't told anyone earlier.

There will always be problems caused by invalid data, corrupt files, typos in scripts/configuration files, unexpected information being returned by COM interfaces and so-on.

You can test your scripts until you are blue in the face, but if your script is running live for two years before you get your first user with an "$" in his name which causes your script to blow up if would be nice if it could alert you rather than silently failing.

This is even more important for stealth scripts with no console.

So, being able to register a handler to deal with unexpected errors and abends is not in itself a bad thing.

Top
#113018 - 2004-02-02 02:39 PM Re: "On Error" function or sub
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I'm inclined to agree with Richard on this one. I'd also like to see events supported as well, but that is another story.
Top
#113019 - 2004-02-02 06:10 PM Re: "On Error" function or sub
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Ultimately, it comes back down to 'sloppy coding' as not every condition had been accounted for. However, it would be nice to have the ability to trap the error and fire off an email.
_________________________
There are two types of vessels, submarines and targets.

Top
#113020 - 2004-02-02 06:36 PM Re: "On Error" function or sub
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Not sure I could lump "imperfect pre-vision" into "sloppy coding".

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#113021 - 2004-02-02 06:46 PM Re: "On Error" function or sub
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
That's why you do
Code:

SELECT
CASE $DefinedCondition
; do stuff
CASE $AnotherDefinedCondition
; do the other stuff
CASE 1
; garbage collection
; do the Macarena and curse the user for incorrect input
ENDSELECT

_________________________
There are two types of vessels, submarines and targets.

Top
#113022 - 2004-02-03 10:19 AM Re: "On Error" function or sub
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Ultimately, it comes back down to 'sloppy coding'




No it doesn't, and simply repeating the statement doesn't make it true.

The point is that there are things that will happen that are beyond your control and which you cannot reasonably script for.

You do not perceive a need because I guess you have not had the experience of function calls returning illegal data which cause problems that you cannot be expected to deal with.

How often do you check in your scripts that UBound() is returning a valid integer before you use it. Never? Well of course you don't - you quite reasonably expect the return value to be as it is documented in the manual.

But what happens when Ubound() returns a garbage string instead? A subtle bug which has been dormant, corrupt DLL, memory error - all these sort of things can cause an error.

Is it sloppy coding because you haven't trapped it? No, it's an unexpected error which you cannot reasonably be expected to code for.

As a simpler example, how do you deal with stack overflows, out of memory errors and the like? You cannot script for them.

Having a catch-all to deal with abends is a nice-to-have. It is by no means a major omission in KiXtart, and there are techniques that can be used to get a near equivalent.

Far from being sloppy coding, having some sort of exception reporting is good technique.

Top
#183683 - 2007-12-14 09:07 PM Re: "On Error" function or sub [Re: Richard H.]
KeithF Offline
Lurker

Registered: 2007-12-14
Posts: 1
I realize that this suggestion is almost 4 years old, but I believe it is still a valid suggestion request.

I've had to inherit some very sloppy code that I would like to be able to have function and trap errors as much as it will take. This way I can log each of the issues and correct them as they're identified.

I find it hard to believe that so Kix can do so much, and the developers are so in tune with the users, that they can't come to develop a function that people want to use...especially when Kix already comes with functions that are 'not required' - I mean, do you really need a function to perform "absolute value" when you can simply write a quick function yourself? Users are asking for this functionality in Kix, and it would be really nice to see it developed.

(thanks)

Top
#184473 - 2008-01-09 12:04 AM Re: "On Error" function or sub [Re: KeithF]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
there also are lots of ppl who don't want it ever to be in kix.
so, you got a code inherited that's screwed up?
and you are going to let it run without even fixing it?
if that's the real deal for "on error", I neither want such thing in kix.
_________________________
!

download KiXnet

Top
#186656 - 2008-04-03 12:51 AM Re: "On Error" function or sub [Re: Lonkero]
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
In Delphi Pascal there is a command called TRY. It has 2 flavours:
This one optionally has a way to return info about the exception.

 Code:
try
    ; do something that shouldn't break, but did once and you have NFI why
except
    ; send an email with info about the failure
end


and
 Code:
; turn something on that needs to be turned off
try
    ; do something that if it fails would abort the sctipt
finally
    ; turn that something off
end


In this case, if the something failed, then the finally...end block would execute, no matter what. You need to be careful not to put anything in that block that depends on the something working of course, but it means you can be sure that your clean up routine always runs.

When I read the OP, it felt like a request for a try...except loop. And I believe it's a good idea. You can't always write code to handle every problem, especially when you are calling out to other code (COM etc). If something fails in that external call, there's no guarantee that your calling process will return politely.

So while you wouldn't go wrapping every single routine in a try loop, some routines that perform tasks whose failure may/should be silent to the user may need to be mentioned to an administrator would be cleanly handled (barring massive kix32.exe failure of course).

Delphi has an exception object that contains info about the type of exception and the actual problem. For example:
 Code:
try
    $myinteger = StringToInteger('1 2')
except on E:Exception do
    ShowMessage('Exception: "' + E.Message + '" of class "' + E.ClassName + '" occured trying to convert')
end


returns a popup message

Exception: "'1 2' is not a valid integer value" of class "EConvertError" occured trying to convert

You can take this to the Nth degree of course:
 Code:
try
    $mystring = 'Convert "' + $userinput + '"'
    $myinteger = StringToInteger($userinput)
    $mystring = 'Call external DLL with ' + $myinteger
    $=ExternalCall($myinteger)
except on E:Exception do
    SendEmail('Exception: ' + E.Message + ' while trying to ' + $mystring)
end;


This method lets you see what the last action attemped was.

my AUD 0.02

cj

Top
#186918 - 2008-04-15 09:30 AM Re: "On Error" function or sub [Re: cj]
Arend_ Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Try was also introduced in the Visual Studio programming languages since 2003, such as VB .Net, C#, etc.

I like to make use of that especially when creating or calling a COM Object. Off course KiX doesn't error out with the creation/calling of COM Objects but it would still be nice to have.

Try...Catch...Finally Statements

Top
#186921 - 2008-04-15 04:34 PM Re: "On Error" function or sub [Re: Arend_]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
That is for good error handling while programming
While scripting, a simple
 Code:
On Error Goto blablabla

could help to write a simple error handler and clean up possible open files or data etc...

Top
#187124 - 2008-04-21 05:33 AM Re: "On Error" function or sub [Re: Witto]
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
I see that as essentially the same thing, but less structured. Is that a naughty word here? Godwin's Law is when someone invokes Hitler, what's the law for invoking Dijkstra \:\)

cj

Top
#187141 - 2008-04-21 06:30 PM Re: "On Error" function or sub [Re: cj]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I also prefer the "Try/Catch" but I don't know if Ruud can implement that. But I presume it is possible to implement the "On Error".
Top
#187274 - 2008-04-24 06:57 PM Re: "On Error" function or sub [Re: Witto]
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
how about

OnError <do this here>

<do this here> could then be left up to the coder... it could be a function.... a snip of code.

or an evil goto

Top
#187279 - 2008-04-24 10:15 PM Re: "On Error" function or sub [Re: Bryce]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
That would be nice.
Just doing "On error resume next" aka "If something is screwed up well....f#ck it. Skip to the next step and you'll never know what went wrong." will not let you learn from your coding mistakes and therefore sucks imho.

But.......
 Code:
OnError Call @scriptdir + “\someotherscript.kix”


or

 Code:
OnError FunctionX($var1, $var2)


or something similar would be useful.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.077 seconds in which 0.022 seconds were spent on a total of 14 queries. Zlib compression enabled.

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