Spread the love
  • 24
  • 28
  • 12
  • 23
  •  
  •  
  •  
  •  
  •  
  •  
    87
    Shares

Tips and Tricks of Error Handling in VBScript or in UFT
Tips and Tricks of Error Handling in VBScript or in UFT

Error Handling in VBScript or in UFT:

Errors are something which is a resultant of deviation from the assumption or requirement or rules via code.It may happen due to syntax mismatch,invalid user input or unavailability of system resources.

Errors in VBScript or UFT are broadly classified as

  • Syntax Error
  • Runtime Error
  • Logic Error

Syntax Error aka Compilation Error

It halts the code execution due to the syntax error. VBScript engine reads the script file and tries to parse the code by converting into meaningful tokens. During this process, if the VBScript engine finds some unacceptable code format due to unrecognizable structure or expressions, it points out this as compilation error or Syntax error.

Example of Syntax error:


Dim myMarks
myMarks=66
If (myMarks>60)
msgbox "Kudos you got 1st division"
End If
 

output:
ErrorCode:800A03F9
Error: Expected Then
Line-3
Character-16

Now as the WSH provides clear error details, it is very easy to detect and rectify the Syntax errors.

Why Syntax Error Occurs?

Below are the prime reasons why Syntax Error happens:

  • If we miss providing mandatory structure information(like keywords, blocks, commas, parenthesis etc)
  • Spelling mistake while using variables, procedures calls, function calls or expressions.
  • Keywords related to other Microsoft tools(Excel, VBA etc) which are not supported by VBScript.
  • Functions related to other Microsoft tools(Excel, VBA etc) which are not supported by VBScript. Mostly these functions need to be defined before using.
  • VBScript has backward compatibility hence versions generally do not play a major role in a Syntax error. But Script written in higher VBScript version may not work well in the lower VBScript versions.
  • Dynamic code generation and execution creates a huge problem in VBScript(command like ExecuteGlobal, Execute or Eval needs extra care).
Common Syntax Error with Error code an Description
Hexadecimal Error CodeDecimal Error CodeComments
800A03E91001“Out of memory” error.
800A040F1039“Invalid ‘exit’ statement” error.
800A03EA1002“Syntax” error.
800A04101040“Invalid ‘for’ loop control variable” error
800A03ED1005“Expected ‘(‘ ” error.
800A04111041“Name redefined” error.
800A03EE1006“Expected ‘)’ ” error.
800A04121042“Must be first statement on the line” error.
800A03F21010“Expected identifier” error.
800A04141044“Cannot use parentheses when calling a Sub” error.
800A03F31011Expected ‘=’ error.
800A03F41012Expected ‘If’ error.
800A04151045“Expected literal constant” error.
800A03F51013“Expected ‘To’ ” error.
800A04161046“Expected ‘In’ ” error.
800A03F61014“Expected ‘End’ ” error.
800A04181048“Must be defined inside a Class” error.
800A04171047“Expected ‘Class’ ” error.
800A03F71015“Expected ‘Function’ “error.
800A04191049“Expected Let , Set , or Get in property
declaration” error.
800A03F81016“Expected ‘Sub’ ” error.
800A03F91017“Expected ‘Then’ ” error.
800A041A1050“Expected ‘Property’ ” error.
800A03FA1018“Expected ‘Wend’ ” error.
800A041B1051“Number of arguments must be consistent across properties specification” error
800A03FB1019“Expected ‘Loop’ ” error.
800A041C1052“Cannot have multiple default property/method in a Class” error,
800A03FC1020“Expected ‘Next’ ” error.
800A041D1053“Class initialize or terminate do not have arguments” error.
800A03FD1021“Expected ‘Case’ ” error.
800A041E1054“Property Set or Let must have at least one argument” error.
800A03FE1022“Expected ‘Select’ ” error.
800A041F1055“Unexpected ‘Next’ ” error.
800A03FF1023“Expected expression” error.
800A04211057” ‘Default’ specification must also specify ‘Public’ ” error.
800A04001024“Expected statement” error.
800A04221058” ‘Default’ specification can only be on property Get” error.
800A04011025“Expected end of statement” error.
800A04021026“Expected integer constant” error.
800A04031027“Expected ‘While’ or ‘Until’ ” error.
800A04041028“Expected ‘While’, ‘Until’, or end of statement” error.
800A04051029“Expected ‘With’ ” error.
800A04061030“Identifier too long” error.
800A04071013“Invalid number” error.
800A04081014“Invalid character” error.
800A04091015“Undermined string constant” error
800A040A1034“Undermined comment” error.
800A040D1037“Invalid use of ‘Me’ keyword” error.
800A040E1038” ‘loop’ without ‘do’ “error.

Runtime Error:

A runtime error occurs when we try to perform a command on an invalid action. These codes get compiled as there is not a Syntax error but failed in the runtime and generate a Runtime error. Runtime errors are not the same as Syntax errors. Here the source information always is “Microsoft VBScript runtime error.”

Runtime errors are not easily detected during the development time of the script.

Runtime errors can be classified as:

  • Non VBScript Runtime error
  • Native VBScript runtime error
  • Variable declaration related due to Option Explicit runtime error.

Non-VBScript Runtime Error

These runtime errors are not generated by the VBScript engine. They are generated by some other components which are attached to VBScript.

Like ADO,ActiveX,DataObject etc

Native VBScript Runtime Error

Native VBScript runtime error happens when the user performs some illegal operations. Mostly these errors are recorded and stored in VBScript Engine.
These errors happen when:

  • One performs wrong arithmetic operations.
  • Read from a database having a null value
  • Keep reading even after the control reached at the End of File.
  • Wrongly used Null in the expressions.
Example of Native Runtime Error

Option Explicit
Dim myVar
myVar=10/0
msgbox "The result is"+ myVar
 

Output:
ErrorCode-800A000B
Error-Division by zero
Line-4
Character-1

Example of Native Runtime Error

Dim myVar
myVar=Null
msgbox "The result is"+ myVar
 

Output:
ErrorCode-800A005E
Error-Invalid Use of Null
Line-4
Character-1

Errors Related to Option Explicit

Option explicit can be a very good tool during the development of the scripts. It acts as a safeguard against accidental spelling mistakes while working with Variables or a strange error which can not be viewed in naked eyes.

Option Explicit also refers to a variable that has not been declared. So if we get a runtime error for option explicit statement that “variable is undefined”.We need to check the declaration of the variables.

Example of Error due to Option Explicit

Option Explicit
Dim index
For index=0 to 10
If(index=5) Then
myVar="Hello"
Msgbox myVar
Else
msgbox index
End If
Next
 

This code will work fine till Index=4. As soon as the index becomes 5, the VBScript engine will throw an error stating myVar variable is undefined. Now if we examine our code carefully, we can see the variable myVar has never been declared.

How to avoid the Runtime Error

Since Runtime is critical than Syntax error, we need to understand how to avoid a Runtime error. Below are the guideline to avoid the runtime error.

  • We need to be well versed with VBScript syntax, rules.
  • We need to carefully read the documentation for functions or sub before working with them.
  • If we get some different, not so well stated error messages or errors like Unspecified errors or Operations aborted or Error occurred etc. we need to surrender to Google. Daddy google has all kind of answer for any sort of problem.
  • The last option is to use a trial and error method. Once we get the different type of solutions from Google we need to apply these techniques in our script.
  • We need to use comments while we fix those errors so that we can later understand the purpose of the code we just inserted to our script.
Common Runtime Errors with Error Code and Description
Hexadecimal Error CodeDecimal Error CodeComments
800A00055“Invalid procedure call / Invalid argument” error.
800A00066“Stack overflow” error.
800A00077“Out of memory” error.
800A00099“SubScript out of Range” error.
800A000A10Array related error -“already locked or fixed” error.
800A000B11“Division by zero” error.
800A000D13“Type mismatch” error
800A000E14“String out of space” error.
800A001117“Can’t perform requested operation” error.
800A001C28“Stack out of space” error.
800A01A8424“Object required” error
800A01AD429“ActiveX component can’t create object” error.
800A01AE430“Class doesn’t support Automation” error.
800A01B0432“Filename or class name not found during
Automation operation” error.
800A002335“Function or sub not defined” error.
800A003048“Error in loading DLL” error
800A003351“Internal” error
800A01B6438“Object doesn’t support this property or method” error.
800A01BD445“Object doesn’t support this action” error.
800A01BF447“Object doesn’t support current locale setting” error.
800A01C0448“Named argument not found” error.
800A01C1449“Argument not optional” error.
800A01C2450“Wrong number of arguments or invalid property assignment” error
800A01C3451“Object not a collection” error.
800A01CA458“Variable uses an Automation type not supported in VBScript” error.
800A01CE462“Remote server machine does not exist or is unavailable” error.
800A01E1481“Invalid picture” error.
800A01F4500“Variable is undefined” error.
800A01F6502“Object not safe for scripting” error.
800A005B91“Object variable not set” error.
800A005E94“Invalid use of Null” error
800A005C92“For loop not initialized” error
800A01F7503“Object not safe for initializing” error.
800A01F8504“Object not safe for creating” error.
800A01F9505“Invalid or unqualified reference” error.
800A01FA506“Class not defined error”.
800A01FB507“An exception occurred error.
800A13905008“Illegal assignment” error.
800A13995017“Syntax error in regular expression”
800A139A5018“Unexpected quantifier” error
800A139B5019Expected ‘]’ in regular expression error.
800A139C5020“Expected  ‘)’ in regular expression” error.
800A139D5021“Invalid range in character set” error.

Logic Errors

Logic errors are very tough to determine especially if a person debugs who never wrote the script. Logic errors are hidden inside our code and generally do not have a User Interface to show up. The only area we understand logic error when the piece of the code generates a wrong output. The output is different from what is desired.

How to avoid logic errors?

  • We need to read the design specification, requirement documentation to understand the functionality and then inspect the code if that is doing what it is suppose to do.
  • We need to follow “Divide and Develop” principal and implement stub and drivers in order to design our script sequentially correct.
  • Check the code logic while using operators. or sendkeys.
  • Use Custom runtime in different places.

How to handle VBScript Errors in UFT or VBScript Editor?

VBScript does not support try-catch block to handle the error or exceptions, instead, it supports to provide a Global error handling mechanism.

What is the Global Error Handling Scheme in VBScript/UFT?

The Global Error Handling Scheme includes:

  • Display the error alert
  • Logging mechanism
  • Email the error
  • Better code design in the error-prone area
  • Use of Err object
  • On Error Statement
Display the error alert

In this mechanism, the VBScript engine displays the error as an alert form. For standalone and small script it serves it purpose but not very effective while scripts are running in a batch mode. It often asks to hide the error. If the error could not be hidden, the execution stops and waits for the alert to be closed. This is a major pain point while running scripts in nightly mode or CDCTCI mode.

Logging mechanism

This is a nice feature to log the error to a different file instead of the display as an alert. The different file can be a flat file or an XML or a database or window event log. This process is hugely used in the current automation scenarios but very laid back or reactive approach.

Email the error

This mechanism puts a little dynamic behavior to the error handling as the moment VBScript encounters an error an email gets triggered /fired to the specified group mentioned earlier. The group can decide the fate of the error then and there.

Better code to handle the error phone area

As and when automation gets matured, the automation engineers can decide where to put an extra set of code to protect known error. This extra set of code put a safety net around the risky code. This approach takes some time to mature and has no immediate implementation. This scheme also greatly depends on the code’s experience.

Use of Err Object

Err is an intrinsic object that has global scope. As a result, it is always available with VBScript Engine in the script. There is an Err object always in the memory. As it is already available and attached to our script, we do not need to create one using CreateObject() to create an Err. We also do not need to have a variable to hold this object.


Spread the love
  • 24
  • 28
  • 12
  • 23
  •  
  •  
  •  
  •  
  •  
  •  
    87
    Shares

19 COMMENTS

  1. What’s up, alwayѕ i used to check webpage posts here early in the morning, since i enjoy to learn more and more.

  2. Ꮋіya! I know this is kinda off topic but I’d figuгed I’d ask.

    Would you be interested in trading links or maybe ɡuеst writing
    a blog article or vice-versa? My site covers a lot of the
    same topics as yours and I think we could greatly benefit fгom each
    otһer. If you might be interested feel free tօ shoot me an email.
    I look forward to һeɑring from you! Ƭerrific blog by the way!

  3. Is primary goal of company earning huge returns?
    Your clients will for you to see the same internet website layout.
    Pick 10-20 publications of one’s topic region and change them in to a
    collection.

    • IsidraFitzmaurice95, Thank you. I am really not looking for huge profit as of right now. I just want to make the website reach in terms of knowledge sharing. However I will surely keep your comment in mind.

      Regards,
      Animesh

  4. I have been browsing online more than 4 hours today, yet I never found any
    interesting article like yours. It’s pretty worth enough for me.
    Personally, if all webmasters and bloggers made good content
    as you did, the web will be much more useful than ever before.
    Howdy! This blog post could not be written any
    better! Looking through this post reminds me of my previous roommate!
    He always kept talking about this. I’ll send this post to him.
    Fairly certain he’s going to have a very good read.

    Thanks for sharing! Howdy just wanted to give you a quick heads up.

    The text in your article seem to be running off the screen in Chrome.
    I’m not sure if this is a formatting issue or something
    to do with internet browser compatibility but I thought
    I’d post to let you know. The design and style look great though!
    Hope you get the problem solved soon. Kudos

  5. Wow! This blog looks exactly like my old one! It’s on a completely different topic but it has pretty
    much the same layout and design. Excellent choice of colors!
    Hello just wanted to give you a quick heads up. The words in your content seem to be running off the screen in Opera.
    I’m not sure if this is a format issue or something to do with web browser
    compatibility but I figured I’d post to let you know.
    The style and design look great though! Hope you get the issue
    resolved soon. Thanks Woah! I’m really digging the template/theme of this site.

    It’s simple, yet effective. A lot of times it’s very difficult to get that “perfect balance”
    between user friendliness and visual appearance.
    I must say you have done a fantastic job with this.
    In addition, the blog loads very quick for me on Opera.
    Superb Blog!

    • Hello Chrinstine,
      I have not checked in Opera till now. Now I got this as a requirement. Surely I will look into this issue. I will rectify if I can.I would suggest to look it at chrome and mozilla.
      Thanks your kind words. It means a lot for a budding blogger like me.

      Regards,
      Animesh

  6. It’s really a great and useful piece of information. I’m glad that you
    simply shared this helpful info with us. Please keep us informed
    like this. Thank you for sharing.

  7. I was curious if you ever thought of changing the layout of your site?
    Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so
    people could connect with it better. Youve got an awful lot of text for only having 1 or 2 pictures.

    Maybe you could space it out better?

  8. Wonderful items from you, man. I’ve understand your stuff prior to and you’re simply too wonderful.
    I really like what you’ve acquired right here, really like
    what you are stating and the way in which during which you
    are saying it. You’re making it enjoyable and you continue to care for to stay it sensible.
    I cant wait to learn far more from you. That is actually a tremendous web
    site.

  9. Wоnderful article! This iѕ the kind of info that should be
    shared aroսnd the net. Shame on the sеek engines for not positioning this submit higher!
    Come on over and seek ɑdѵice from mʏ site .
    Ꭲһanks =)

  10. There has been a lot of fuss about SEO or search
    engine optimization. Some would say it would take months and even years to
    be one important the search engines even though some even claim it would certainly
    be just a matter of weeks for you to view results and dominate Google which
    is which?

    Link exchanging with other blogs in which in equivalent market as yours.
    You are unable to want any that price range direct competition with remember.
    This can help you out if these linked sites have a good page ranking in Google
    or other popular search engines.

    The success of your article really depends onto your headline (title).

    This just what the user sees . Make sure you grab their undivided attention so they will want to read
    your article. 75% of as well as effort writing your article often be spent on creating a title.

    Without a successful page, positive if you find it difficult to
    make quick money online. The landing page is come into making cash.

    Don’t give poor effort in completing this method. It is a substantial reason for the downfall many Internet marketing
    campaigns.

    You are afraid to be an expert on google marketing added with these techniques either.
    A person have know basic HTML, you’ll be able to can implement these goes.

    So maybe you should activate with just adding say Meta tags and seeing
    how that gets an outcome when copy and paste a associated with your
    pages text within a search locomotive. Then change the Meta tags to another thing and re-submit your
    pages to figure out. Next time you execute a search
    the new same keyword and key phrase as before, you will have a choice of could be getting
    you the best information.

    Email marketing or advertising. Some online users do don’t
    have much time to check your own everyday notice your
    latest offerings. Bring the content to them, right inside mailbox by
    sending them email advertising.

    For details on the best way to resize your Headline tags and correct use of hyperlinks using
    Dreamweaver booking out our article ‘Optimizing in Dreamweaver for Dummies’.

LEAVE A REPLY

Please enter your comment!
Please enter your name here