Forum Discussion

mrezahoseini's avatar
mrezahoseini
Contributor
10 years ago
Solved

Exception Handling

Hello,

 

How to handle exceptions in our programs? I wouldn't like my program to be stopped by exception, I also disabled(off) stop on error option and used event handleder for unexpected windows. But I don't know how to manage exceptions.

 

Thanks in advance 

 

Best 

  • Hi,

     

    You must clearly understand and distinguish between the possible reasons of test failures and handle them appropriately.

    So, the test may fail / stop when:

    1) The runtime error occurs in the test code. For example, test code tries to use undeclared variable, or divide by zero, or call undefined function, etc. These are purely failures of the given scripting language and can be handled either by corrections of the code or by the relevant language means (try/catch, On Error Resume Next, etc.), though this latter approach is highly not recommended;

    2) The tested object was not found but test code tries to use its properties / methods (e.g. the message window was not found but test code tries to close it through the call to its .Close method). Again, these are purely failures of the given scripting language and can be handled either by corrections of the code, or by prior checking if the sought for object and its parents were found (through the use of the .Exists property) or by the relevant language means (try/catch, On Error Resume Next, etc.), though again, this latter approach is highly not recommended;

    3) The action against the UI element cannot be performed because the target UI element is blocked by the modal window (for example, test code tries to .Click some UI element, but this is not possible because this UI element is blocked by some warning message window). This problem can be handled with the use of different OnLogXXX event handlers (OnUnexpectedWindow event handler for the given case) and through the relevant Project Properties|Playback settings. Note, that OnUnexpectedWindow event is triggered only when an action is performed against the blocked UI element. If the test code calls some internal method of the blocked UI element (e.g. .SetText method), the event will not be triggered;

    4) An internal exception occurs in the tested application (e.g. the tested application tries to divide by zero and does not handle this situation gracefully). This is internal problem of the tested application and must be corrected by developers, though you may try to detect the crash window shown by either OS or your tested application and continue correspondingly. Also you may try to use the Project Properties|Freeze Diagnostics functionality of TestComplete.

1 Reply

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    You must clearly understand and distinguish between the possible reasons of test failures and handle them appropriately.

    So, the test may fail / stop when:

    1) The runtime error occurs in the test code. For example, test code tries to use undeclared variable, or divide by zero, or call undefined function, etc. These are purely failures of the given scripting language and can be handled either by corrections of the code or by the relevant language means (try/catch, On Error Resume Next, etc.), though this latter approach is highly not recommended;

    2) The tested object was not found but test code tries to use its properties / methods (e.g. the message window was not found but test code tries to close it through the call to its .Close method). Again, these are purely failures of the given scripting language and can be handled either by corrections of the code, or by prior checking if the sought for object and its parents were found (through the use of the .Exists property) or by the relevant language means (try/catch, On Error Resume Next, etc.), though again, this latter approach is highly not recommended;

    3) The action against the UI element cannot be performed because the target UI element is blocked by the modal window (for example, test code tries to .Click some UI element, but this is not possible because this UI element is blocked by some warning message window). This problem can be handled with the use of different OnLogXXX event handlers (OnUnexpectedWindow event handler for the given case) and through the relevant Project Properties|Playback settings. Note, that OnUnexpectedWindow event is triggered only when an action is performed against the blocked UI element. If the test code calls some internal method of the blocked UI element (e.g. .SetText method), the event will not be triggered;

    4) An internal exception occurs in the tested application (e.g. the tested application tries to divide by zero and does not handle this situation gracefully). This is internal problem of the tested application and must be corrected by developers, though you may try to detect the crash window shown by either OS or your tested application and continue correspondingly. Also you may try to use the Project Properties|Freeze Diagnostics functionality of TestComplete.