Re: Thoughts on current error handling best practice with VBScript
- From: "Paul Randall" <paulr901@xxxxxxxxxxxx>
- Date: Sun, 3 Feb 2008 16:00:02 -0700
"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
.
- Follow-Ups:
- Re: Thoughts on current error handling best practice with VBScript
- From: Todd Vargo
- Re: Thoughts on current error handling best practice with VBScript
- References:
- Thoughts on current error handling best practice with VBScript
- From: FUBARinSFO
- Re: Thoughts on current error handling best practice with VBScript
- From: ekkehard.horner
- Re: Thoughts on current error handling best practice with VBScript
- From: FUBARinSFO
- Thoughts on current error handling best practice with VBScript
- Prev by Date: Re: File Size Check
- Next by Date: Re: Thoughts on current error handling best practice with VBScript
- Previous by thread: Re: Thoughts on current error handling best practice with VBScript
- Next by thread: Re: Thoughts on current error handling best practice with VBScript
- Index(es):
Relevant Pages
|