cancel
Showing results for 
Search instead for 
Did you mean: 

How to catch errors and exceptions

Valued Contributor

How to catch errors and exceptions

Hi,

Untill now I catch errors with the OnError event.

But I need to perform a method on "OnError", a method that is in the script.

Please consider this code :

 

procedure TestErrorException;
begin
  try
    // Goes to OnError event : not ok
    Aliases.MyExe.FormCptReciproque.PanelBas.XPBitBtnSaisieEcr.Click();
    
    //Goes to the finally : ok
    a_variable:= 0;
    
    //Goes to the finally : ok
    raise('I raise an exception');
    
  finally
    Log.Message('I need to go there in every case');
  end;
end;

 

I try to make for every case the procedure going to the finally. It works well in the case 2 and 3, but in case of not finding an object, it raises an error that trigger the OnError event.

But I still need to be into the call method, before the event to performs some steps.

Any help would be greatly appreciated

 

8 REPLIES 8
Community Leader

Re: How to catch errors and exceptions

If it's on intercepting not found error you can modify your onError event.

I suggest you to look at this thread.

 

As for me to fully control the error flow I use a mix between a global variable storing the last error object (null if no error), the try..catch syntax and the onError event.

Un sourire et ça repart

Valued Contributor

Re: How to catch errors and exceptions

The problem is that I need variables that are specific to the test item, and thus available only in the test item...

Community Hero

Re: How to catch errors and exceptions

Hi,

 

Your code should pass through the finally statement for all three cases. It might terminate immediately if you have your project's/test item's setting to stop on error, but even in this case I would expect finally statement to execute and I would consider this behavior as DelphiScript's flaw and contact Support (https://support.smartbear.com/message/?prod=TestComplete) for their confirmation (and, hopefully, fix).

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Valued Contributor

Re: How to catch errors and exceptions

Hi Alex,

Thank you for replying,

In the OnLogError I had a Runner.Stop(True).

I understand that with this statement TC would stop and not go to the finally.

But I tried to remove it, and the main procedure just continues.

I tried to put a "raise" in OnLogError and the main procedure still continues without going instantly to the finally.

I wrote to the support...

Community Hero

Re: How to catch errors and exceptions

Hi  Mehdi,

 

I tried to put a "raise" in OnLogError and the main procedure still continues without going instantly to the finally.

I have a strong feeling that several years ago there was a breaking change in DelphiScript engine (not sure was it for purpose or not) that unhandled exception thrown in some called script unit stopped to be traced back to the caller parent one that contains exception handling structures. This is how DelphiScript functioned initially for a lot of years.

I would really hope that guys will be able to correct this behavior while working on your case.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Community Manager

Re: How to catch errors and exceptions

@m_essaid I see you opened a support ticket and the investigation there started. We would really appreciate it if you posted the solution you get from support here, thank you!


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Valued Contributor

Re: How to catch errors and exceptions

Hi Sonya,

I didn't received any solution from the support team.

They say this is "due to engine specifics".

Community Manager

Re: How to catch errors and exceptions

@m_essaid this is unfortunate! Thank you for sharing with us.


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors