Catch Operation

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

Use the Catch operation along with the Try and Finally operations to implement the structured exception handling mechanism in your keyword tests.

  • The Try operation groups operations that may cause an error.

  • The Catch operation contains operations that will be executed if an error occurs in the Try block. These operations can, for example, stop the test execution or send a notification to the tester.

  • The Finally block contains operations that will be executed regardless of whether an error occurs in the Try block.

The example of using the Try, Catch, and Finally operations

Click the image to enlarge it.

After an error has been handled by operations of the Catch block, TestComplete continues the test execution from the next operation as if no error occurred.

Note that the Try and Catch operations only handle exceptions raised by the test engine, like an incorrect number of parameters specified for a test operation or incorrect parameter types, syntax errors in code expressions embedded in the test and others. They do not handle errors that are posted to the test log by TestComplete test objects, methods and properties, like “Object not found”, “Object does not support this property or method” and the like. To handle these errors, create an event handler for the OnLogError event (see About Events and Event Handling).

Requirements

The Catch operation must be preceded by the related Try operation and must reside at the same level.

Operation Result

The operation returns information on the error that occurred within the Try block. What information the operation returns depends on the Last Result value.

For information on how to obtain the result value, see Checking Operation Result.

Scripting Analogue

The Catch operation is similar to the catch statement of C++ or C#, or to the except statement of Delphi.

Child Operations

The Catch operation can have any other operations as children.

For information on how to make an operation a child of another operation, see the description of the Keyword Test editor’s Test Steps page.

Operation Parameters

The operation has only one parameter:

Specifying the Catch parameters

Last result

Specifies what information is returned. The following options are available:
  • Error Code - A unique identifier of the error. For example, 2147418113.

  • Description - A description of the error (default). For example, An error occurred while executing the code snippet: ReferenceError: badFunction is not defined.

  • Full information - Includes the message type (exception, error and so on), the error code and the description of the error. For example, Exception(-2147418113) An error occurred while executing the code snippet: ReferenceError: badFunction is not defined.

To learn how to get information on the occurred error, see Checking Operation Result.

See Also

Statements Category
Try Operation
Finally Operation

Highlight search results