Book Image

Advanced UFT 12 for Test Engineers Cookbook

Book Image

Advanced UFT 12 for Test Engineers Cookbook

Overview of this book

Table of Contents (18 chapters)
Advanced UFT 12 for Test Engineers Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Catching errors inside a function or subroutine


In this recipe, we will learn how to implement an error trap inside a function or subroutine.

Getting ready

From the File menu, navigate to New | Function Library... or use the Alt + Shift + N shortcut. Name the new function library ErrHandling_Func.vbs. You can use any other name, or reuse an existing function library. Do not forget to ensure that the library is attached to the test through Resources (File | Settings | Resources).

How to do it...

The technique is very simple. First, within your function, identify the line or lines of code that carry the potential of raising an exception (for example, an unhandled error). For instance, we write the following simple function to perform a division operation:

Function DblDivideXByY(x, y)
    'Return the result of the division as a Double
    DivideXByY=CDbl(x/y)
End function 

The problem with the preceding code is that it assumes a priori that the parameters passed to the function are valid. However...