Jump to content

What does ObjEvent ("AutoIt.Error", "__UserComError") DO


Recommended Posts

KK, thanks dale. Thats cleared that up!

I think I'm going to have it so the function returns an error if ones already there, rather than creating an error. Or find a workaround...

@Storme,

Didn't someone find a way that worked by checking for errors whilst using RunAs??

MDiesel

Link to comment
Share on other sites

@Storme,

Didn't someone find a way that worked by checking for errors whilst using RunAs??

MDiesel

No that was for checking the username/password (IE the _UserPasswordIsValid function) and it doesn't work with blank passwords. It just throws an error, when you try and use a blank password....sigh

All we really need to know is IF a password is SET.......ANYONE have any ideas?

John Morrison

Link to comment
Share on other sites

The way we have works, so if anyone wants the functions and their own com error, then they'll have to set the variable again afterwards!

I could add an optional parameter so you can restore the original error handler properly.

Something like:

Command ("", $Param, "oMyError")

Execute ($ & $p3) = ...

not a good representation i know

MDiesel

Link to comment
Share on other sites

The way we have works, so if anyone wants the functions and their own com error, then they'll have to set the variable again afterwards!

I could add an optional parameter so you can restore the original error handler properly.

Something like:

Command ("", $Param, "oMyError")

Execute ($ & $p3) = ...

not a good representation i know

MDiesel

Not a bad idea! It's 2AM here but I couldn't go to bed without testing it.

@DaleHohm THANKS for the info about dealocating the ORIGINAL variable (that fact had eludeded me).

@MDiesel Take note of the dealocating and realocating I did in the test code. :)

Anyway here is my test code and proof of concept.

You should get 3 errors 1st form the main code using it's error handler, 2nd from the function using it's error handler and the 3rd from the main code using it's error handler..... ALL WORKING :-)

Global $oMyError
Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.

Local $oMyErrFunc = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler

; Performing a deliberate failure here (object does not exist)
$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.bogus
;If $g_eventerror Then MsgBox(0, "First Error", "the previous line got an error.")
$oIE.quit ; Quit IE
$oIE = 0 ; Remove IE from memory (not really necessary)
$g_eventerror = 0

;Perform my test
test($oMyErrFunc)
If $g_eventerror Then MsgBox(0, "PROBLEM", "the previous function..... YOU shouldn't see this!!!")
$g_eventerror = 0

; Performing a deliberate failure here (object does not exist)
$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.REALbogus
;If $g_eventerror Then MsgBox(0, "SECOND ERROR", "the previous line got an error.")
$oIE.quit ; Quit IE
$oIE = 0 ; Remove IE from memory (not really necessary)

Exit

Func test(ByRef $oMyErrorOld_OBJ)
    MsgBox(0, "test Function", "START")
    Local $oMyErrorOld = ObjEvent("AutoIt.Error") ; Backup previous error handler
    $oMyErrorOld_OBJ = 0 ; dealocate ErrorHandler
    $oMyError = ObjEvent("AutoIt.Error", "ComError") ; Set new error handler

    $oIE = ObjCreate("InternetExplorer.Application")
    $oIE.visible = 1
    $oIE.REALbogus
    ;If $g_eventerror Then MsgBox(0, "SECOND ERROR", "the previous line got an error.")
    $oIE.quit ; Quit IE
    $oIE = 0 ; Remove IE from memory (not really necessary)

    MsgBox(0, "test Function", "TEST - DONE")
    
    $oMyError = 0 ; dealocate ErrorHandler
    $oMyErrorOld_OBJ = ObjEvent("AutoIt.Error", $oMyErrorOld) ; Restore old error handler
    MsgBox(0, "test Function", "Reset Errorhandler - DONE")
EndFunc   ;==>test

Func ComError()
    ConsoleWrite("HELLO from ComError" & @CR)
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "", "ComError intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "Windescription is: " & $oMyError.windescription)

    ConsoleWrite("ComError intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "Windescription is: " & $oMyError.windescription & @CR)
EndFunc   ;==>ComError

; This is my custom error handler
Func MyErrFunc()
    ConsoleWrite("HELLO from MyErrFunc" & @CR)
    $HexNumber = Hex($oMyErrFunc.number, 8)
    MsgBox(0, "", "MyErrFunc intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "Windescription is: " & $oMyErrFunc.windescription)

    ConsoleWrite("MyErrFunc intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "Windescription is: " & $oMyErrFunc.windescription & @CR)

    $g_eventerror = 1 ; something to check for when this function returns
EndFunc   ;==>MyErrFunc

Good Luck

John Morrison

Link to comment
Share on other sites

  • 2 weeks later...

Not a bad idea! It's 2AM here but I couldn't go to bed without testing it.

@DaleHohm THANKS for the info about dealocating the ORIGINAL variable (that fact had eludeded me).

@MDiesel Take note of the dealocating and realocating I did in the test code. :party:

Anyway here is my test code and proof of concept.

You should get 3 errors 1st form the main code using it's error handler, 2nd from the function using it's error handler and the 3rd from the main code using it's error handler..... ALL WORKING :-)

CODE
Global $oMyError

Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.

Local $oMyErrFunc = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler

; Performing a deliberate failure here (object does not exist)

$oIE = ObjCreate("InternetExplorer.Application")

$oIE.visible = 1

$oIE.bogus

;If $g_eventerror Then MsgBox(0, "First Error", "the previous line got an error.")

$oIE.quit ; Quit IE

$oIE = 0 ; Remove IE from memory (not really necessary)

$g_eventerror = 0

;Perform my test

test($oMyErrFunc)

If $g_eventerror Then MsgBox(0, "PROBLEM", "the previous function..... YOU shouldn't see this!!!")

$g_eventerror = 0

; Performing a deliberate failure here (object does not exist)

$oIE = ObjCreate("InternetExplorer.Application")

$oIE.visible = 1

$oIE.REALbogus

;If $g_eventerror Then MsgBox(0, "SECOND ERROR", "the previous line got an error.")

$oIE.quit ; Quit IE

$oIE = 0 ; Remove IE from memory (not really necessary)

Exit

Func test(ByRef $oMyErrorOld_OBJ)

MsgBox(0, "test Function", "START")

Local $oMyErrorOld = ObjEvent("AutoIt.Error") ; Backup previous error handler

$oMyErrorOld_OBJ = 0 ; dealocate ErrorHandler

$oMyError = ObjEvent("AutoIt.Error", "ComError") ; Set new error handler

$oIE = ObjCreate("InternetExplorer.Application")

$oIE.visible = 1

$oIE.REALbogus

;If $g_eventerror Then MsgBox(0, "SECOND ERROR", "the previous line got an error.")

$oIE.quit ; Quit IE

$oIE = 0 ; Remove IE from memory (not really necessary)

MsgBox(0, "test Function", "TEST - DONE")

$oMyError = 0 ; dealocate ErrorHandler

$oMyErrorOld_OBJ = ObjEvent("AutoIt.Error", $oMyErrorOld) ; Restore old error handler

MsgBox(0, "test Function", "Reset Errorhandler - DONE")

EndFunc ;==>test

Func ComError()

ConsoleWrite("HELLO from ComError" & @CR)

$HexNumber = Hex($oMyError.number, 8)

MsgBox(0, "", "ComError intercepted a COM Error !" & @CRLF & _

"Number is: " & $HexNumber & @CRLF & _

"Windescription is: " & $oMyError.windescription)

ConsoleWrite("ComError intercepted a COM Error !" & @CRLF & _

"Number is: " & $HexNumber & @CRLF & _

"Windescription is: " & $oMyError.windescription & @CR)

EndFunc ;==>ComError

; This is my custom error handler

Func MyErrFunc()

ConsoleWrite("HELLO from MyErrFunc" & @CR)

$HexNumber = Hex($oMyErrFunc.number, 8)

MsgBox(0, "", "MyErrFunc intercepted a COM Error !" & @CRLF & _

"Number is: " & $HexNumber & @CRLF & _

"Windescription is: " & $oMyErrFunc.windescription)

ConsoleWrite("MyErrFunc intercepted a COM Error !" & @CRLF & _

"Number is: " & $HexNumber & @CRLF & _

"Windescription is: " & $oMyErrFunc.windescription & @CR)

$g_eventerror = 1 ; something to check for when this function returns

EndFunc ;==>MyErrFunc

Good Luck

John Morrison

Interesting idea for a work-around, and a nice demo too. :idea:

Since you can't have an optional ByRef input variable (as mdiesel pointed out), it would be a script-breaking change for Dale, for example, in IE.au3. Scripts already coded with simply _IEErrorHandlerRegister() would be broken until changed to _IEErrorHandlerRegister("") if he implemented this in the next version of IE.au3.

Implementing this across all scripts requires every scripter to subscribe to the convention of either using the exact same Global variable (I called it $oAutoItCOMError in BugTrac #838), or always passing their other chosen Global to error handler registering functions ByRef as in this example here. This would not change/fix anything in AuotIt itself, it would just be a convention among the users.

The Devs, or at least Valik as far as he has commented on it, want it REALLY fixed. Not just a Global variable work-around.

[speculation on things that are over my head...]

As far as I understand it, that means it may be possible (one day, after a rewrite of AutoIt's COM error handling) to register more than one error handler. They would form a "stack" of handlers that would receive the error in turn. Each would check if it came from the COM object that handler was written for (IE, MSXML, Excel, ADSI, etc.), and either handle it or pass it on to the rest of the stack. There would be new functions for it. Something like a COMErrorHandlerRegister(), which would register a handler into the stack and return a handle whose only use is for later removing that handler from the stack by passing it to something like a COMErrorHandlerDeregister().

All the UDFs you put at the top of your script could then register their own handlers, and none need awareness of the others, except to be well behaved about not interfering with the stack of handlers.

[/speculation]

The smart people can tell me if that makes any sense.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...