genius257

Is it possible to throw an error in a ScriptControl object, via AutoIt

1 post in this topic

#1 ·  Posted (edited)

First of all I've been searching on the forum, and while there's been done something like this with: https://www.autoitscript.com/forum/topic/141004-comobject-proxy-seamless-windows-script-control-autoitobj/

I could not find any solution to my predicament.

 

Is it possible to throw an error in a ScriptControl object, via AutoIt?

I have a script, where AutoIt calls ScriptControl:JavaScript which in turn calls AutoIt.

However i would like to be able to make AutoIt invoke an exception within ScriptControl, if the called functionality fails.

Here's some code for reference:

#AutoIt3Wrapper_Run_AU3Check=n

#include-once
#include "AutoitObject.au3"
#include <WinAPIDiag.au3>

$oJS = ObjCreate("ScriptControl")
$oJS.Language = "JScript"
$oJS.TimeOut = 0; A value of 0 means that the ScriptControl will monitor the execution of the script and will trigger the Timeout event if it determines that the script is hung.
_AutoItObject_Startup()
$oAutoIt = _AutoItObject_Create()
_AutoItObject_AddMethod($oAutoIt, "Execute", "_Execute", False)
$oJS.AddObject("AutoIt", $oAutoIt, True)

OnAutoItExitRegister("_CleanUp")

$_AutoItError = ObjEvent("AutoIt.Error", "_AutoItError")

Func _CleanUp()
    ConsoleWrite("Cleaning up..."&@CRLF)
    $oJS = 0
    $oAutoIt = 0
    _AutoItObject_Shutdown()
EndFunc

Func _Execute($oSelf, $sString)
    $vReturn = Execute($sString)
    If @error<>0 Then Return $oJS.Eval("throw new SyntaxError();"); Does invoke exception, but not within the try/catch
    Return $vReturn
EndFunc

Func _AutoItError($oError)
    $oError2 = $oJS.Error
    ConsoleWrite( _
        "Column: " & $oError2.Column & @CRLF & _
        "Description: " & $oError2.Description & @CRLF & _
        "HelpContext: " & $oError2.HelpContext & @CRLF & _
        "HelpFile: " & $oError2.HelpFile & @CRLF & _
        "Line: " & $oError2.Line & @CRLF & _
        "Number: " & $oError2.Number & @CRLF & _
        "Source: " & $oError2.Source & @CRLF & _
        "Text: " & $oError2.Text & @CRLF _
    )
    $oError2.Clear()
EndFunc

$oJS.Eval("(function(){"& _
    "try{"& _
        "AutoIt.Execute('MsgBox(0,\'\', \'a\')');"& _
        "AutoIt.Execute('a.b');/*error should occur here*/"& _
        "AutoIt.Execute('MsgBox(0,\'\', \'b\')');"& _
    "}catch(e){"& _
        "AutoIt.Execute('ConsoleWrite(\'Error\'&@CRLF)');"& _
    "}"& _
"})()")

 

Edited by genius257

Share this post


Link to post
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

  • Similar Content

    • Swatcat
      By Swatcat
      Hi All,
      So I need Help.
      I am developing code to handle Authentication Popup For IE. The issue I am facing is that this code runs smoothly on unlock desktop but fails on VM machine and when machine is locked. So could you suggest what should I do to make it work. My automation Tool is a Selenium Based tool and is able to launch the script, but the AutoIT Script is unable to pass the username and password on the authentication popup.
      Below is the code.
      I am passing the values through Command line arguments.
      #include <Array.au3> Local $browser, $BAuthMode, $BWinAuthUserName, $BWinAuthPassword, $BChromeClaimsURL, $BChromePolicyURL, $BIEPolicyURL, $BIEClaimsURL; $browser = $CMDLine[1] $BAuthMode = $CMDLine[2] $BWinAuthUserName = $CMDLine[3] $BWinAuthPassword = $CMDLine[4] $BChromeClaimsURL = "" $BChromePolicyURL = "" $BIEURL = "" ;$BIEClaimsURL = "" If $browser = "chrome" And $BAuthMode = "m" Then If WinExists($BChromeClaimsURL,"") Then WinWaitActive($BChromeClaimsURL) ; set control to the window for proxy authentication Sleep(500) Send("{ESCAPE}") ElseIf WinExists($BChromePolicyURL,"") Then WinWaitActive($BChromePolicyURL) ; set control to the window for proxy authentication Sleep(500) Send("{ESCAPE}") EndIf ElseIf $browser = "ie" And $BAuthMode = "m" Then If WinExists($BIEPolicyURL,"") Then WinExists($BIEPolicyURL) ; set control to the window for proxy authentication Sleep(500) Send("{ESCAPE}") ElseIf WinExists($BIEClaimsURL,"") Then WinWaitActive($BIEClaimsURL) ; set control to the window for proxy authentication Sleep(500) Send("{ESCAPE}") EndIf ElseIf $browser = "ie" And $BAuthMode = "w" Then WinWaitActive($BIEURL,"","20") if(WinExists($BIEURL)) Then Sleep(500) Send($BWinAuthUserName & "{TAB}") ; send username and press TAB Sleep(100) Send($BWinAuthPassword & "{ENTER}") ; send the password and press enter Sleep(100) EndIf ElseIf $browser = "chrome" And $BAuthMode = "w" Then If WinExists($BChromeClaimsURL,"") Then WinWaitActive($BChromeClaimsURL) ; set control to the window for proxy authentication Sleep(500) Send($BWinAuthUserName & "{TAB}") ; send username and press TAB Send($BWinAuthPassword & "{ENTER}") ; send the password and press enter ElseIf WinExists($BChromePolicyURL,"") Then WinWaitActive($BChromePolicyURL) ; set control to the window for proxy authentication Sleep(500) Send($BWinAuthUserName & "{TAB}") ; send username and press TAB Send($BWinAuthPassword & "{ENTER}") ; send the password and press enter EndIf EndIf WinSetState("[ACTIVE]", "", @SW_RESTORE) Sleep(500) WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)  
       
       
       
    • Gowrisankar
      By Gowrisankar
      Dear members of the forum,
      I'm new to AutoIt and I'm having a good time exploring and enjoying the features of AutoIt.
      For one of my tasks, I've to open few particular mails from outlook based on subject of the mails and then print the mails. Can someone please guide me how to do it?
      My question could be very silly for experts. But I'm just a beginner. Kindly advice.
      Thanks and regards,
      Gowrisankar R.
    • Valnurat
      By Valnurat
      I have a
      Global $aResult[0][2] For $i = 0 to UBound($aNames) -1 Local $aUserInfo = _AD_GetObjectsInOU($aNames[$i],"","","displayName,distinguishedName") _ArrayDisplay($aUserInfo) _ArrayConcatenate($aResult, $aUserInfo, 1) _ArrayDisplay($aResult, 'AD ' & UBound($aResult)) Next I do receive empty info that's added to my array.
      How can I delete empty records?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I'd like to know if someone else here has already tried to use an AutoIt script which work on the same DB ( i.e. SQLite ) on different Computers.
      If yes, please answer here, because I'd like to develop it, and I don't know where to start ( i.e. , I don't know how the script would work if 2 or more users are writing/reading in the same moment... )  
      Thanks! 
    • Valnurat
      By Valnurat
      Hi experts.
      I'm sorry if this has been explained before.
      I have a list of dates. Some are like this: YYYY/MM/DD and that is ok. But then I have some like this: DD/MM/YYYY and that is not ok.
      I want to go through the list in convert it to YYYY/MM/DD.
      How do you convert DD/MM/YYYY to YYYY/MM/DD?