Forum Discussion

Hardy's avatar
Occasional Contributor
7 years ago

Why except block won't executed when an error occurs within try block?

I am testing window application, and use try...except...finally to catch errors during run script test. But now it won't execute except block when an error occurs within try block, please refer to attached scripts and screenshot for more details.

2 Replies

  • shankar_r's avatar
    Community Hero


    As far as i know, This expected behavior only. The errors coming from test are not actually a exception hence it will not throw a run-time error.


    Some of the errors are not part of RunTime error

    • Object Not Found
    • Unable to Recognize the Image on the Current Desktop
    • Search for a Mapped Object Took Too Much Time
    • The test run has stopped because the Stop on Error (Warning) setting is enabled
    • Incomplete Keyboard Input
    • There was an attempt to perform an action at point...
    • The window is invisible and thus cannot be activated
    • and more..

    Basically, Python or any other language can't capture some of the Test Complete Playback errors.


    More details: 


    Some related topics:

    • tristaanogre's avatar
      Esteemed Contributor

      What shankar_r says is accurate.  try/except logic, regardless of the language, will only trap actual runtime code exceptions.  Errors logged due to object identification errors as listed or any other errors logged via TestComplete do not throw an exception.


      If you want a particular error to throw an exception, you'll have to use the associated "throw" or "raise" command according to your code language.