Opened on Mar 29, 2026 at 4:33:45 PM
Last modified on Mar 29, 2026 at 7:59:58 PM
#4083 new Bug
COM Error Handler - not always fires event - when assigning values
| Reported by: | mLipok | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.18.0 | Severity: | None |
| Keywords: | Cc: |
Description (last modified by )
This issue is continuation for:
https://www.autoitscript.com/trac/autoit/ticket/3167
Please check this repro script:
Global $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", _ComErrorHandler) Global $oFake[] Global $oTestObject[] $oFake.TestObject = $oTestObject $oFake.TestObject.Check1 = 1 $oFake.FakeObject = 1 ConsoleWrite($oFake.FakeObject.Check2 & @CRLF) ; _ComErrorHandler() is not fired even this was already fixed in https://www.autoitscript.com/trac/autoit/ticket/3167 $oFake.FakeObject.Check3 = 1 ; _ComErrorHandler() is not fired and AutoIt ends with "Variable must be of type "Object"" Func _ComErrorHandler(ByRef $oError) #forceref $oError ConsoleWrite("! We intercepted a COM Error" & @CRLF) EndFunc ;==>_ComErrorHandler
IMHO both .Check2 and .Check3 should fires _ComErrorHandler() and show the console message.
Disscusion was taken on the forum here:
https://www.autoitscript.com/forum/topic/213563-catching-com-errors-when-assigning-a-value-to-chained-object
ps.
sorry for so many edits.
Attachments (0)
Change History (7)
comment:1 by , on Mar 29, 2026 at 4:34:45 PM
| Description: | modified (diff) |
|---|
comment:2 by , on Mar 29, 2026 at 4:37:12 PM
| Description: | modified (diff) |
|---|
comment:3 by , on Mar 29, 2026 at 4:41:26 PM
| Description: | modified (diff) |
|---|
comment:4 by , on Mar 29, 2026 at 4:48:58 PM
| Description: | modified (diff) |
|---|
comment:5 by , on Mar 29, 2026 at 4:50:18 PM
| Description: | modified (diff) |
|---|
comment:7 by , on Mar 29, 2026 at 7:59:58 PM
most complex example:
https://www.autoitscript.com/forum/topic/213563-catching-com-errors-when-assigning-a-value-to-chained-object/page/2/#findComment-1551168
| Line | |
|---|---|
| 1 | #include <AutoItConstants.au3> |
| 2 | |
| 3 | Global $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", _ComErrorHandler) |
| 4 | |
| 5 | Global $oMAP_object[] |
| 6 | Global $oTestObject1_Shell = ObjCreate("shell.application") |
| 7 | Global $oTestObject2_Map[] |
| 8 | Global $_WatchPoint = @ScriptLineNumber |
| 9 | |
| 10 | #Region ; testing FIX https://www.autoitscript.com/trac/autoit/ticket/3167 |
| 11 | $_WatchPoint = @ScriptLineNumber |
| 12 | ;~ $oTestObject1_Shell.Explore(@ScriptDir) ; works |
| 13 | |
| 14 | $_WatchPoint = @ScriptLineNumber |
| 15 | $oTestObject1_Shell.Windows().Item(666).bzzzzzzz ; _ComErrorHandler() IS FIRED and AutoIt PROPERLY continue processing next line - due COM ERROR HANDLER was used and FIXED in #3167 |
| 16 | |
| 17 | $_WatchPoint = @ScriptLineNumber |
| 18 | $oTestObject1_Shell.Windows().Item(666).bzzzzzzz = 1 ; _ComErrorHandler() IS FIRED and AutoIt PROPERLY continue processing next line - due COM ERROR HANDLER was used and FIXED in #3167 |
| 19 | #EndRegion ; testing https://www.autoitscript.com/trac/autoit/ticket/3167 |
| 20 | |
| 21 | $_WatchPoint = @ScriptLineNumber |
| 22 | $oMAP_object.Shell = $oTestObject1_Shell |
| 23 | |
| 24 | $_WatchPoint = @ScriptLineNumber |
| 25 | $oMAP_object.Shell.Explore(@ScriptDir) ; works |
| 26 | |
| 27 | $_WatchPoint = @ScriptLineNumber |
| 28 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.Shell", VarGetType($oMAP_object.Shell)) |
| 29 | |
| 30 | $_WatchPoint = @ScriptLineNumber |
| 31 | ; _ComErrorHandler() IS FIRED and AutoIt PROPERLY continue processing next line - due COM ERROR HANDLER was used and FIXED in #3167 |
| 32 | $oMAP_object.Shell.Fake1(@ScriptDir) |
| 33 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.Shell.Fake1(@ScriptDir)", '') |
| 34 | |
| 35 | $_WatchPoint = @ScriptLineNumber |
| 36 | ; _ComErrorHandler() IS FIRED and AutoIt PROPERLY continue processing next line - due COM ERROR HANDLER was used and FIXED in #3167 |
| 37 | $oMAP_object.Shell.Fake2 = 2 |
| 38 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.Shell.Fake2 = 2", '') |
| 39 | |
| 40 | $_WatchPoint = @ScriptLineNumber |
| 41 | ; _ComErrorHandler() IS FIRED and AutoIt PROPERLY continue processing next line - due COM ERROR HANDLER was used and FIXED in #3167 |
| 42 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.Shell.Fake3", $oMAP_object.Shell.Fake3) |
| 43 | |
| 44 | $_WatchPoint = @ScriptLineNumber |
| 45 | $oMAP_object.TestObject2_Map = $oTestObject2_Map |
| 46 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.TestObject2_Map", VarGetType($oMAP_object.TestObject2_Map)) |
| 47 | |
| 48 | $_WatchPoint = @ScriptLineNumber |
| 49 | $oMAP_object.TestObject2_Map.Check1 = 1 ; create MAP element called "Check1" with value = 1 |
| 50 | |
| 51 | $_WatchPoint = @ScriptLineNumber |
| 52 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.TestObject2_Map.Check1", $oMAP_object.TestObject2_Map.Check1) |
| 53 | |
| 54 | $_WatchPoint = @ScriptLineNumber |
| 55 | MsgBox(0, @ScriptLineNumber & " : $oTestObject2_Map.Check1", $oTestObject2_Map.Check1) |
| 56 | |
| 57 | $_WatchPoint = @ScriptLineNumber |
| 58 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.TestObject2_Map.Check1", $oMAP_object.TestObject2_Map.Check1) |
| 59 | |
| 60 | $_WatchPoint = @ScriptLineNumber |
| 61 | $oMAP_object.FakeObject1 = 1 ; create MAP element called "FakeObject" with value = 1 |
| 62 | |
| 63 | $_WatchPoint = @ScriptLineNumber |
| 64 | ; in the following line _ComErrorHandler() IS NOT FIRED although it has already been fixed in https://www.autoitscript.com/trac/autoit/ticket/3167 = IMHO this is AutoIt issue |
| 65 | ; ... but maybe it is intentional to not FIRE _ComErrorHandler() as $oMAP_object.FakeObject1 is treated as MAP ELEMENT thus Check2 is also treated as MAP element and thus can be created on the fly |
| 66 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.FakeObject1.Check2", "Result=" & $oMAP_object.FakeObject1.Check2) |
| 67 | |
| 68 | $_WatchPoint = @ScriptLineNumber |
| 69 | ; _ComErrorHandler() IS FIRED and AutoIt PROPERLY continue processing next line - due COM ERROR HANDLER was used and FIXED in #3167 |
| 70 | MsgBox(0, @ScriptLineNumber & " : $oCOM_ErrorHandler.FakeObject1.Check3", $oCOM_ErrorHandler.FakeObject1.Check3) |
| 71 | |
| 72 | $_WatchPoint = @ScriptLineNumber |
| 73 | ; in the following line _ComErrorHandler() IS FIRED but AutoIt ends with (Variable must be of type "Object") = IMHO this is AutoIt issue |
| 74 | ; ... this is the case @donnyh13 reported at the begining = IMHO this is AutoIt issue |
| 75 | $oCOM_ErrorHandler.FakeObject2.Check4 = 1 |
| 76 | MsgBox(0, @ScriptLineNumber & " : $oCOM_ErrorHandler.FakeObject2.Check4", "") |
| 77 | |
| 78 | $_WatchPoint = @ScriptLineNumber |
| 79 | ; _ComErrorHandler() IS FIRED and AutoIt PROPERLY continue processing next line - due COM ERROR HANDLER was used and FIXED in #3167 |
| 80 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.FakeObject3.Check5", $oMAP_object.FakeObject3.Check5) |
| 81 | |
| 82 | $_WatchPoint = @ScriptLineNumber |
| 83 | ; in the following line _ComErrorHandler() IS NOT FIRED and AutoIt ends with (Variable must be of type "Object") = IMHO this is AutoIt issue |
| 84 | ; ... this is the case @donnyh13 reported at the begining = IMHO this is AutoIt issue |
| 85 | $oMAP_object.FakeMapElement.Check6 = 1 |
| 86 | MsgBox(0, @ScriptLineNumber & " : $oMAP_object.FakeMapElement.Check6", "") |
| 87 | |
| 88 | Func _ComErrorHandler(ByRef $oError) |
| 89 | #forceref $oError |
| 90 | ConsoleWrite("! We intercepted a COM Error : Last @ScriptLineNumber (WatchPoint) =" & $_WatchPoint & @CRLF) |
| 91 | EndFunc ;==>_ComErrorHandler |
#REMARK => .Check2 needs To be explained
#REMARK => both .Check4 and .Check6 should fires _ComErrorHandler() and show the console message also AutoIt should not ends With: Variable must be of type "Object"

Global $oCOM_ErrorHandler = ObjEvent("AutoIt.Error", _ComErrorHandler) ; line 1 Global $oShell = ObjCreate("shell.application") ; line 2 $oShell.FakeObject = 1 ; line 3 $oShell.FakeObject.Check3 = 1 ; line 4 ConsoleWrite("hello" & @CRLF) ; line 5 Func _ComErrorHandler(ByRef $oError, $iLine = @ScriptLineNumber) #forceref $oError ConsoleWrite('"' & @ScriptFullPath & '" (' & $iLine & ") : We intercepted a COM Error " & @CRLF) EndFunc ;==>_ComErrorHandler..that is a simpler example (from a forum post)https://www.autoitscript.com/forum/topic/213563-catching-com-errors-when-assigning-a-value-to-chained-object/page/2/#findComment-1551164
For now we can wrap it in Execute() to avoid the crash while it gets fixed.