Forum Discussion

d_dimalanta's avatar
d_dimalanta
Occasional Contributor
14 years ago

Catching Errors

Hello,



I have a winform object that I try assigning to a var.

Now this object may or may not exist.



When the object does not exist and is being assigned to a var, the test stops executing

and an error "Unable to find the object..." is produced in the log.



This is suitable in certain test cases. However, there are cases where

I don't need the whole test to stop executing because a certain winform cannot be found

(and where a warning may / or may not be needed).





I tried putting the assignment in a try / catch block as seen below, however it seems that a variable assignment error isn't handled the same way as exceptions.


  try

  {

    btn_forgotPass = passW.WinFormsObject("_btnForgotPassword");

  }

  catch(e){  

    btn_forgotPass == null;  

  }


Any suggestions? 



thanks,

Daryl


  • Hi,



    The try/catch block doesn't catch regular scripting errors which are not exceptions. You need to obtain your object by using the WaitWinFormsObject method and check its result's Exists property value.
  • sgoodman's avatar
    sgoodman
    New Contributor
    Why are regular scripting errors not exceptions?  It seems arbitrary that this particular case would be treated as a regular scipriting error rather than treating it as an exception and allowing me to handle it a manner useful to my test.



    In my particular case, the process is busy causing this object to become unusable.  I could get around this by increasing the Options.Run.Timeout to something much much higher.  However, I am trying to move my code to a script extension to make it shareable and I have not yet found away change playback properties from a script extension.



    Ideally, this, and all script "regular" errors would be treated as exceptions unless I specfically say its an error via Log.Error().
  • d_dimalanta's avatar
    d_dimalanta
    Occasional Contributor
    Thanks!  This solved my issues with obtaining winform objects.