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: ...

Get Advanced UFT 12 for Test Engineers Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.