Programmatically getting the line number of an error in VBScript

Posted on 2009-02-20
Last Modified: 2012-08-14
Basically, I want my script to log any errors it encounters and log the line number of the error.  I'd like to do this just using VBScript.  Is this possible?
Question by:judgeking
    LVL 15

    Expert Comment

    LVL 6

    Author Comment

    Thanks, but I'm already doing this type of error checking, what I want is something like this:
    'main VBScript code here
    '... some code
    '... some more code
    If Err.Number <> 0 Then
       LogError Err.Number, Err.Description, Err.LineNumber
    End If

    Open in new window

    LVL 65

    Accepted Solution

    Hi, there is no line number property, but you can try using the Source property to determine which object raised the error.

    Otherwise you'd have to put in your own line number indicators.  For example, in judgeking's code above, you'd use something like
    LogError "Error " & Err.Number & " was raised on line 6."

    but that, of course, requires that you manually update the string each time you change the code.


    LVL 65

    Expert Comment

    Oh, you *are* judgeking....ignore that bit... :-)
    LVL 6

    Author Comment

    OK, I didn't think it was possible to get the line number, but I just wanted a second opinion.  Thanks.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
    I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now