Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Error Handling - on error goto Label?

Error Handling - on error goto Label?

Error Handling - on error goto Label?

Within VBS, is it possible to provide my own error handling, such:

on error goto myerrorhandle

if Err.Number=3 then
  echo "Oh no, not good"
  echo "Not so bad, but not great."
end if

RE: Error Handling - on error goto Label?

Hello MCubitt,

Vbs does not support On Error Goto Label directive. Instead, it is not difficult to implement the functionality. Something like this illustrate the idea.

set fso=createobject("scripting.filesystemobject")
on error resume next
set f=fso.opentextfile("nonexisting.txt")
select case errcode
    case 53
                call errorhandle_53
        'case etc...
    case else
        msgbox err.number & vbcrlf & err.description
        'do something / call some routine
end select
'some other stuff
on error goto 0
'do some other stuff
set f=nothing
set fso=nothing

sub errorhandle_53    'file not found
    msgbox err.number & vbcrlf & err.description
        'do something useful
end sub

RE: Error Handling - on error goto Label?

On VBS you can only use this syntax:
On Error Resume Next
On Error GoTo 0

The Err object is available:
On Error Resume Next
Err.Raise 3
Msg="Error# " & CStr(Err.Number) & " " & Err.Description _
 & " from " & Err.Source
WScript.Echo Msg

Hope This Help

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close