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.
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).
The Catch operation must be preceded by the related Try operation and must reside at the same level.
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.
The Catch operation is similar to the
catch statement of C++ or C#, or to the
except statement of Delphi.
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.
The operation has only one parameter:
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.