Forum Discussion

ChristophGoetz's avatar
ChristophGoetz
New Contributor
4 years ago
Solved

A recursive call to an event_handler has been detected

Hi, i have created an event that reacts to a timeout error. Unfortunately it always comes to the message from the title. I can't find out what the reason could be? I call nothing recusively. I only ...
  • AlexKaras's avatar
    4 years ago

    Hi,

     

    As the message says, event handling procedure appears to be called recursively.

    To provide you with more detailed answer, more details from you would be great: what type of event, code, screenshot of the tested application at the moment of error, etc.

     

    Possible scenario as an example:

    -- for the OnLogError event handler;

    -- if the error occurs within the event handler's code (e.g. if the code attempts to click something and the click fails);

    -- then the OnLogError will be triggered again, which will cause another attempt to click, which will fail and result in recursive call.

     

    To handle the above scenario:

    -- Either ensure that no error can happen in the event handler's code; or

    -- Introduce a flag that will indicate whether or not event handling is active. Set the flag when entering event handler and clear it when leaving. Event handler's code must exit (with possible message to test log) if recursive call is detected.

    Sample pseudocode:

    var bOnErrorFlag = false; // flag that preserves its value between calls to OnLogErrorHandler() function

     

    function OnLogErrorHandler(...)

    {

      if (bOnErrorFlag)

      {

        Log.Warning('Recursive call to OnLogError. Event handler exited'); // Log.Error() must not be used!

        exit;

      }

      bOnErrorFlag = true;

      ...

      bOnErrorFlag = false;

    }