Forum Discussion

MulgraveTester's avatar
MulgraveTester
Frequent Contributor
7 years ago

Event handlers - choose code resumption point

When my event handler detects that the test application has crashed, rather than halt execution (runner.halt) I need to flag that the app has crashed so that no more actions are applied to it until it is restarted. My problem is that I cannot know when the app crashes and therefore cannot prevent code, that references destroyed objects, from causing errors.

 

How can I force my event handler to resume at a given point?

 

appHasCrashed = false

DO While some logic applies
   'IF THE GUI CRASHES I WANT THE EVENT HANDLER TO RESUME EXECUTION HERE
   Identify the GUI and its components

   IF not appHasCrashed then
      Select case TheNextTestStep
          case DoThis
             call DoThis
   
          case DoThat
            call DoThat
   

         case DoSomethingElse
           call DoSomethingElse
      end select

   end if
Loop

 

sub DoThis
   set someObj = GUI.window(windowID)
   call mySubroutine(someObj)
end sub

 

sub mySubroutine(someObj)
   set subObj1 = someObj.window(subitem1) 'Let's say that the GUI crashes here.

   'If I resume on the next line I'll just end up with a fatal error. I want to resume in a safe location 2 calls above here.
   set subObj2 = someObj.window(subitem2)
   set subObj3 = someObj.window(subitem3)
end sub

 

Sub GeneralEvents_OnLogError(Sender, LogParams)
   log.warning("The GUI failed")
   appHasCrashed = true

   'I'd like to resume in a safe location but will resume on the next line of code after the error - which will lead me to a fatal error.
end sub 

1 Reply

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    The "OnLogError" event handler does exactly that... executes something when an error is written to the log.  It has limited awareness of what caused the error.

     

    To do what you want, instead of depending upon the event handler, write your automation code to use exception handling to deal with these unexpected situations.  Your MySubroutine would have this exception  handling in it.