|
-
Jan 10th, 2011, 07:00 PM
#1
Thread Starter
New Member
VBScript Error Logging problem when using Err.Raise
Sorry about the fact this is probably quite a basic question!
I'm playing around with error logging in VBScript and I can't get it to log an error after I use err.raise to create one. If I comment out the Err.Raise it writes to the logfile with no error information. If I comment out the 'On Error Resume Next' but leave the Err.Raise uncommented an error is generated.
I am using VBS Edit to write the script.
Script is:
-------------------------------------
Option Explicit
On Error Resume Next
Dim objWshShl, objFsoObject, objLogFile
Set objWshShl = WScript.CreateObject("WScript.Shell")
Set objFsoObject = WScript.CreateObject("Scripting.FileSystemObject")
'Main Processing Section
Subroutine()
WScript.Quit()
'Procedure Section
Function Subroutine()
Err.Raise(6)
If (objFsoObject.FileExists("C:\ErrorLog.txt")) Then
Set objLogFile = objFsoObject.OpenTextFile("C:\ErrorLog.txt", 8)
Else
Set objLogFile = objFsoObject.OpenTextFile("C:\ErrorLog.txt", 2, True)
End If
objLogFile.WriteLine "Test.vbs Error: " & Err.Number & ", Description = " & Err.Description & " , Source = " & Err.Source
objLogFile.Close
Err.Clear
End Function
----------------------------
Any ideas? I'm sure it's something basic I'm doing wrong.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|