#113016 - 2004-02-02 05:47 AM
Re: "On Error" function or sub
|
Kdyer
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
|
Top
|
|
|
|
#113017 - 2004-02-02 10:33 AM
Re: "On Error" function or sub
|
Richard H.
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
|
|
|
|
#113022 - 2004-02-03 10:19 AM
Re: "On Error" function or sub
|
Richard H.
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
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
|
|
|
|
#186656 - 2008-04-03 12:51 AM
Re: "On Error" function or sub
[Re: Lonkero]
|
cj
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.
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
; 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:
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:
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_
MM club member
Registered: 2005-01-17
Posts: 1895
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
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
That is for good error handling while programming While scripting, a simple
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
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
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 370 anonymous users online.
|
|
|