Re: on error resume next
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 11 Feb 2006 13:01:07 -0600
Hi,
My philosophy is to never use On Error Resume Next except on a statement I
expect could raise an error under certain conditions (like the DC is not
available, or the user supplied bad imput). I always trap the error
condition, then restore normal error handling with On Error GoTo 0.
This means that my production scripts (and programs) can show error
messages. I know some consider this unsightly, but my opinion is that I'd
rather have the user call with an error message (which usually leads me
right to the problem), than call to say it doesn't work with no clue why.
Some of my scripts are used by school children, and I'd still rather know
there is a problem, rather than pretend there isn't. This also helps me
learn from problems, and be more carefull when I code.
If you want a switch to turn error handling on and off, a global boolean
could do that. VB has more functionality, where you can use "On Error GoTo
ErrorRoutine", but this is not available in VBScript. .NET has something
even better. Even in VB I display an error message so the user can give me a
clue about the problem. Otherwise, I have to restore the error handling, and
if the problem cannot be duplicated easily, I'm stuck.
The only time I can see where you want a production script to use On Error
Resume Next is where you truely want the script to never halt. Just my
opinion, but I think the coder is lazy. A lot of damage could result, or at
least the results could be wrong or incomplete. Just my opinion.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
"Big D" <BigDaddy@xxxxxxxxxxxxxxxx> wrote in message
news:u4GdqszLGHA.3260@xxxxxxxxxxxxxxxxxxxxxxx
I am asking for advice when using On Error Resume Next.
I have written a very extremly long vbscript with many Subs/Functions.
Within each of the subs/functions I leave On Error Resume Next commented
out until I feel confident the script is functioning and I catch the
obvious issues. Once ready I enable "On Error Resume Next" with in all the
sub/functions.
Now since being used in production the script encountered a issue and it
happens its not an error I expected, so since On error command is used the
script continues even though there is an error. (As expected) To
troubleshoot the issue I had to comment out all the On Error lines to
actually disply the issue running.
In short when using On Error command is there any easier or better
approach when using On Erorr command and not having to comment the line
out.
My thoughts were to create a Constant OnError = True or False that is
gloabal, Then each time the command is used, do the following
Constant OnError = False
If OnError = True
On Error Resume Next
End If
I just don't know if thats the best away to approach and asking for any
ideas. The If statement will be teh same for each sub/function. A lot of
duplication of statement.
.
- Follow-Ups:
- Re: on error resume next
- From: Alan Gillott
- Re: on error resume next
- References:
- on error resume next
- From: Big D
- on error resume next
- Prev by Date: on error resume next
- Next by Date: How to save command output
- Previous by thread: on error resume next
- Next by thread: Re: on error resume next
- Index(es):
Relevant Pages
|