Forum Discussion

Hardy's avatar
Hardy
Occasional Contributor
8 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.

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

    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: https://support.smartbear.com/testcomplete/docs/testing-with/running/handling-errors/index.html 

     

    Some related topics:

    https://community.smartbear.com/t5/TestComplete-Functional-Web/Handling-Object-Not-Found-Errors-via-Exceptions/td-p/88070

    • tristaanogre's avatar
      tristaanogre
      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.