Try-Catch not working in TestComplete

990 views Asked by At

In test complete I am trying to use a try-catch block to see if a message box has an okay button and then click the okay button without crashing. I put the click operation inside a try block so if it fails the catch block can deal with the error, but it is crashing inside the try block. Here's an example:

try
{
    okayButton = SomeLocation;
    okayButton.click();
}
catch(err)
{
    do something;
}

I would think that when Test Complete can't click the okay button, it would move into the catch block. However, I get an error on the okayButton.click(); line, which stops the test run. It says "there was an attempt to preform an action on a zero-sized window.". Does anyone know how do deal with this? Thanks in advance.

1

There are 1 answers

1
taxicala On BEST ANSWER

If okayButton.click(); does not throw an err, Your catch block will never be executed. You should validate that when okayButton.click(); fails, it throws the error your catch block is expecting.

It may be that okayButton.click(); is returning the error instead of throwing it.