Hasoth

Error handling - because of wrong type scrip gets terminated ignoring ObjEvent

3 posts in this topic

Hi,

I think I've tried all example on the forum and internet and I still can't make error handling work if there's object error. My example when Script gets terminated and ErrorFunction is not triggered

 

$objErr = ObjEvent("AutoIt.Error","MyErrFunc")

Local $amyArray [1] = ["My string"]
local $vSomeValue = $amyArray[0].className ; will give error because there's a string not object type

Func MyErrFunc()
    $hexnum=hex($objErr.number,8)

    Msgbox(0,"","We intercepted a COM Error!!"        & @CRLF                   & @CRLF & _
                 "err.description is: "    & $objErr.description    & @CRLF & _
                 "err.windescription is: " & $objErr.windescription & @CRLF & _
                 "err.lastdllerror is: "   & $objErr.lastdllerror   & @CRLF & _
                 "err.scriptline is: "     & $objErr.scriptline     & @CRLF & _
                 "err.number is: "         & $hexnum                 & @CRLF & _
                 "err.source is: "         & $objErr.source         & @CRLF & _
                 "err.helpfile is: "       & $objErr.helpfile       & @CRLF & _
                 "err.helpcontext is: "    & $objErr.helpcontext _
                )

    Exit
    SetError(1)
EndFunc

All I get is information about termination

"D:\AutoIt\test.au3" (4) : ==> Variable must be of type "Object".:
local $vSomeValue = $amyArray[0].className
local $vSomeValue = $amyArray[0]^ ERROR
->11:41:03 AutoIt3.exe ended.rc:1
+>11:41:03 AutoIt3Wrapper Finished.

Any idea how to handle it? I'm used to VBA and there "On Error GoTo Handler" works all the time no matter what type of error I get.

Share this post


Link to post
Share on other sites



The AutoIt.Error  handler is only for trapping errors that occur  within COM objects. For all other errors you have to write code to handle them and take appropriate action, wherever they might occur. AutoIt has no equivalent of VBs On Error GoTo.

Example:

$objErr = ObjEvent("AutoIt.Error","MyErrFunc")

Local $amyArray [1] = ["My string"]
local $vSomeValue = 0
If Not IsObj($amyArray[0]) Then
    Msgbox(0,"","$amyArray[0] Is not an object")
Else
    $vSomeValue = $amyArray[0].className
EndIf

Func MyErrFunc()
    $hexnum=hex($objErr.number,8)

    Msgbox(0,"","We intercepted a COM Error!!"        & @CRLF                   & @CRLF & _
                 "err.description is: "    & $objErr.description    & @CRLF & _
                 "err.windescription is: " & $objErr.windescription & @CRLF & _
                 "err.lastdllerror is: "   & $objErr.lastdllerror   & @CRLF & _
                 "err.scriptline is: "     & $objErr.scriptline     & @CRLF & _
                 "err.number is: "         & $hexnum                 & @CRLF & _
                 "err.source is: "         & $objErr.source         & @CRLF & _
                 "err.helpfile is: "       & $objErr.helpfile       & @CRLF & _
                 "err.helpcontext is: "    & $objErr.helpcontext _
                )

    Exit
    SetError(1)
EndFunc

 


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Thank you very much for the answer :) I thought so, but I didn't want to wrongly assume.

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