Quit VBScript On Error

Posted on 2007-10-03
Last Modified: 2012-06-21
How can I quit the vbscript on error instead of resume next?

I've tried a few variations and nothing works.

I tried:
On Error GoTo Quit

Function Quit()
End Function

On Error GoTo 5

5 WScript.Quit
Question by:MDauphinais1
    LVL 6

    Accepted Solution

    Nope, sorry.  Only 2 options with VBS -- handle each possible error or ignore all errors.  GoTo 0 is the only GoTo option -- it doesn't really mean the same as a GoTo to redirect -- but totally understand what you're attempting.  It just means the opposite of resume next, instead of continuing it throws an ugly error to the user.
    There are limitations/tradeoffs for not having a full blown compiler.

    The only good thing is that the On Error is not a one time statement.  You can switch back in forth in your script.
    If there's a particular place in code you are concerned with you can turn Resume Next on just before and turn it off after, otherwise it gets pretty laborious.  No nice global catches.

    On Error Resume Next
    AvgResult = a/b
    If Err.Number > 0
    End If
    On Error GoTo 0
    LVL 65

    Expert Comment

    itdrms is right.
    Omitting any On Error Resume Statement will stop VBScript continuing, and upon any error, it will crash out with the error message.

    The only way to do it in a user friendly manner is to use the code itdrms provided, at a place where you expect an error may occur.



    Author Comment

    Hmm..... ok.  Thanks for the help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
    Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now