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