Modify

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#3841 closed Bug (No Bug)

COM Error Handling

Reported by: kAnon Owned by:
Milestone: Component: AutoIt
Version: 3.3.14.5 Severity: None
Keywords: Cc:

Description

Error handler does not work with array elements.

#include <StringConstants.au3>

test()

Func test()
    Local $oComError = ObjEvent('AutoIt.Error', onComError)
    #forceref $oComError

    Local $oObject
    Local $aoObjects[1]
    $oObject.TestComError() ; error handled
    $aoObjects[0].TestComError() ; error not handled
EndFunc   ;==>test

Func onComError($oComError)
    With $oComError
        ConsoleWrite(@ScriptName & ' (' & .ScriptLine & ') : ==> COM Error intercepted !' & @CRLF & _
                @TAB & '.Number:' & @TAB & @TAB & '0x' & Hex(.Number) & @CRLF & _
                @TAB & '.WinDescription:' & @TAB & StringStripWS(.WinDescription, BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING, $STR_STRIPSPACES)) & @CRLF & _
                @TAB & '.Description:' & @TAB & @TAB & .Description & @CRLF & _
                @TAB & '.Source:' & @TAB & @TAB & .Source & @CRLF & _
                @TAB & '.HelpFile:' & @TAB & @TAB & .HelpFile & @CRLF & _
                @TAB & '.HelpContext:' & @TAB & @TAB & .HelpContext & @CRLF & _
                @TAB & '.LastDllError:' & @TAB & @TAB & .LastDllError & @CRLF & _
                @TAB & '.ScriptLine:' & @TAB & @TAB & .ScriptLine & @CRLF & _
                @TAB & '.RetCode:' & @TAB & @TAB & '0x' & Hex(.RetCode) & @CRLF & @CRLF)
        SetError(.Number)
    EndWith
EndFunc   ;==>onComError

Console output

... : ==> COM Error intercepted !
    .Number:         0x000000A9
    .WinDescription: Variable must be of type 'Object'.
    .Description:
    .Source:
    .HelpFile:
    .HelpContext:
    .LastDllError:   0
    .ScriptLine:     1
    .RetCode:        0x00000000

... (12) : ==> Variable must be of type "Object".:
$aoObjects[0].TestComError()
$aoObjects[0]^ ERROR

Windows 10 Pro 21H1 x64
AutoIt Version: 3.3.14.5 / 3.3.15.4

Attachments (0)

Change History (3)

comment:1 by jchd18, 5 years ago

The description is a little wrong: the issue arises only with an uninitialized variable in an array and TestComError applied to it.

The following works correctly, which is a more real-world situation. Non-objects variables can't invoke a COM error handler by themselves, so that IFAIK only the TestComError method can make this minor problem show up.

Func test()
    Local $oComError = ObjEvent('AutoIt.Error', onComError)
    #forceref $oComError

    Local $oObject = ObjCreate("shell.application")
    Local $aoObjects = [$oObject]
    $oObject.TestComError() ; error handled
    $aoObjects[0].TestComError() ; error not handled
EndFunc   ;==>test

comment:2 by J-Paul Mesnage, 5 years ago

Resolution: No Bug
Status: newclosed

comment:3 by kAnon, 5 years ago

It's still inconvenient to work with arrays of objects. Why is the behavior different for an array cell and a regular variable?

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.