Re: Thoughts on current error handling best practice with VBScript

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"FUBARinSFO" <file1303@xxxxxxxxx> wrote in message
news:7a2f0ed5-6af3-4b4e-a523-244cb17942cf@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Paul Randall has suggested reading the remarks in the script56.chm
file concerning the On Error statement.

Thanks for the feedback. I think it evoked inspired responses from
the heavyweights of this newsgroups.

Here is a short script that demonstrates a few effects of VBScript's
error handling. One problem I find while writing this kind of thing
is documenting it. Adding comments to the script, or echoing more
information can lead to a less understandable script. And a separate
text document to explain what is happening doesn't work well without
line numbered source code to refer to.

'Simple non-exhaustive test of 'On Error Resume Next'
' on subroutine calls.
Option Explicit
On Error Resume Next
Wscript.Echo "Started script"
ErrorSub1
Wscript.Echo "Wscript.Echo 1 - Back in Main from ErrorSub" &
Err.Number
Err.Clear
ErrorSub2
Wscript.Echo "Wscript.Echo 2 - Back in Main from ErrorSub" &
Err.Number
Err.Clear
ErrorSub3
Wscript.Echo "Wscript.Echo 3 - Back in Main from ErrorSub" &
Err.Number
Err.Clear
WScript.Echo "Reached end of script"
WScript.Quit

Sub ErrorSub1()
WScript.Echo "Entered ErrorSub1"
Err.Raise 1
Wscript.Echo "This statement never executed - Exitting Sub1"
End Sub

Sub ErrorSub2()
WScript.Echo "Entered ErrorSub2"
Err.Raise 2
Wscript.Echo "This statement never executed - Exitting Sub2"
End Sub

Sub ErrorSub3()
WScript.Echo "Entered ErrorSub3"
On Error Resume Next
EroorSub1 'Purposely misspelled subroutine name
Wscript.Echo "Wscript.Echo 4 - Back in ErrorSub3 from Sub" &
Err.Number
Err.Clear
ErrorSub1
Wscript.Echo "Wscript.Echo 5 - Back in ErrorSub3 from Sub" &
Err.Number
Err.Clear
On Error Goto 0
ErrorSub1
Wscript.Echo "This statement never executed - Exitting Sub3"
End Sub


.



Relevant Pages

  • Re: Thoughts on current error handling best practice with VBScript
    ... information can lead to a less understandable script. ... Sub ErrorSub1() ... WScript.Echo "Entered ErrorSub1" ... this code demonstrates how NOT to implement error handling. ...
    (microsoft.public.scripting.vbscript)
  • Re: Thoughts on current error handling best practice with VBScript
    ... information can lead to a less understandable script. ... Sub ErrorSub1() ... WScript.Echo "Entered ErrorSub1" ... this code demonstrates how NOT to implement error handling. ...
    (microsoft.public.scripting.vbscript)
  • Re: Detecting is hyperthreading is enabled with WMI?
    ... It is too bad that WMI does not give this info. ... have to be done to the script. ... Public Sub DisplayProcessorInfo ... dim ProcessorSet, Processor ...
    (microsoft.public.windowsxp.wmi)
  • Cant make this page work
    ... I can't make this script work properly. ... The script at the bottom of the html page ... Does someone have a perl ... sub output_trace_headers { ...
    (comp.lang.javascript)
  • Re: Maybe I should try a different approach
    ... entire time my script is running, then have it close when my script is done and maybe have some dots keep adding to the text message until the script is fully completed? ... ' The "Three Ugly Hack" Script, ... Sub oATO_vbTimerEvent' timer event handler... ... Public Property Let Left ...
    (microsoft.public.scripting.vbscript)