Jump to content

Error Handling in Code - (Moved)


Recommended Posts

Hello,

I have below code which execute well when all prerequisite met, when window pop up is not available its throwing an error. i want to capture error instead of error  out.

error handling added in the code to capture it but it does not work still giving me error saying Variable must be of type "Object".

$oCurWin.FindAll($treescope_subtree, $oCondition, $pElements)
$oCurWin^ ERROR

How to catch error properly . 

 

Quote

 

#include <UIAWrappers.au3>
#include <ScreenCapture.au3>
#include<_XMLDomWrapper.au3>
#include <Array.au3>
#include <Inet.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <WinAPIFiles.au3>

$name=@ComputerName
$result="Pass"
$String=""
$Timeout = 50

AutoItSetOption("WinTitleMatchMode",2)

Global $pSelect, $oSelect , $sIID_IUIAutomationInvokePatternId,$dtagIUIAutomationInvokePatternId , $TypeofButton , $sButtonAutoID

Func GetTimeoutValue($WinTitle , $BtnName, $TypeofButton="AutoID")

      WinWait ( $WinTitle , "" , 10)
      WinActivate($WinTitle)
      WinActivate($WinTitle)
      $oCurWin = _UIA_wdaObjUsingName("WdaCustomMessageBox")

      Dim $pTrueCondition, $pElements, $iLength = 0, $pUIElement, $jLength = 0
      $objUIAutomation.CreateTrueCondition($pTrueCondition)
      $oCondition = ObjCreateInterface($pTrueCondition, $sIID_IUIAutomationCondition, $dtagIUIAutomationCondition)
      $oCurWin.FindAll($treescope_subtree, $oCondition, $pElements)
      If @error Then MyErrFunc(@ScriptLineNumber, @error) ;check for error
         Return
      EndIf

      $oAutomationElementArray = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
      $oAutomationElementArray.Length($iLength)
      ConsoleWrite($iLength&@CRLF)
      Next
EndFunc


$BtnName = "timeOutLb"
;~ $BtnName = "MessageText"
$result = GetTimeoutValue("Wyse Device Agent : Software Update Alert" ,$BtnName)

Func MyErrFunc($iLineNumer, $iError)
   $iLineNumer = $iLineNumer - 1
   MsgBox(0, "", "ERROR GENERATED ON SCRIPT LINE: " & $iLineNumer & @CRLF & "ERROR CODE: " & $iError)
EndFunc   ;==>MyErrFunc

 

 

 

 

Edited by PramodR
Link to comment
Share on other sites

Search for COM error handler.  or do your own variable validating with functions like IsObj () prior to assuming what the contents of the variable are

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

ObjEvent in the help file is your friend :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...