01-13-2014 07:41 AM
Hi,
is there any coding way to extract the exact position where an error occured in the script? You usually get the position and the script name displayed in the LogFile, but apparently this does not happen when "On Error Resume Next" is enabled.
What I am trying to achieve is that a message with all error information is being sent out as soon as an error occurs. Message sending works but the information I can currently grab are only Err.Description, Err.Number and Err.Source which does not help me very much as I cannot localise it.
Anyone with an idea?
/Phex
01-13-2014 06:30 PM
Phex
Here is a link on Error trapping in VB script from the best person I know about for VB script.
http://blogs.msdn.com/b/ericlippert/archive/2004/08/19/error-handling-in-vbscript-part-one.aspx
Paul
01-15-2014 12:05 PM
Hi Phex,
Within the On Error Resume Next ... On Error Goto 0 structure the Err object is available for reading and setting error states, like this:
Dim Result, ErrNum, ErrMsg, ErrSrc, Msg On Error Resume Next Result = 9/0 ' questionable command line ErrNum = Err.Number ErrMsg = Err.Description Errsrc=Err.Source On Error Goto 0 IF ErrNum <> 0 THEN Msg = "Error occured" & vbCRLF Msg = Msg & "Number = " & ErrNum & vbCRLF Msg = Msg & "Message = " & ErrMsg & vbCRLF Msg = Msg & "Source = " & ErrSrc & vbCRLF MsgBox Msg END IF
I strongly recommend you surround only the select command(s) you expect might throw an error. You'll cause yourself no end of trouble if you just turn on On Error Resume Next at the top of your script and never turn it off, or if you surround 20 or 30 lines of code with the error handling.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
01-15-2014 01:08 PM
Thanks for the input Brad, but it seems quite exausting to equip all probable error sources with a surrounding "On Error"-handling.
Do you know how DIAdem itself extracts the error information? I am particularly looking for that type of phrase e.g. "Error in <track_sub_20140113.VBS> (Line: 3260, Column: 3)"
/Phex
01-16-2014 11:16 AM
Hi Phex,
I don't know how DIAdem extracts the error information. Ideally you would not have that many possible error sources in your code. Would it be possible to turn some of that error-prone code into a Subroutine and call it multiple times? That way the error handling would just be in the Subroutine once.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
01-16-2014 12:02 PM - edited 01-16-2014 12:03 PM
Hm.. Right now I do not see this working very well as even subroutines have gotten quite long occasionally and as per Murphy's law you will most probably do not get an error where you have expected it. I guess for the time being the best is to turn off error resuming completely and cross fingers that everything works - or if not then handle each error at a time based on DIAdem's location message and restart the script.
/Phex