Sign in to follow this  
Followers 0
pdaughe

COM Error Handling

18 posts in this topic

If you look at this thread:

http://www.autoitscript.com/forum/index.ph...c=50240&hl=

you see that I've been struggling with handling COM errors in AutoIt. If you have experienced the same, you may try what I found to be the solution:

Simply by replacing the statement:

ObjEvent ("AutoIt.Error", "Error_Handler")

with

$My_Error = ObjEvent ("AutoIt.Error", "Error_Handler")

the error handler intercepts the COM error, as expected.

Perhaps it's a requirement to save the object name, but it wasn't apparent....

Share this post


Link to post
Share on other sites



For some reason, even with this, the errors aren't caught in a compiled script..

Is there a way to catch the COM errors in a compiled script?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

For some reason, even with this, the errors aren't caught in a compiled script..

Is there a way to catch the COM errors in a compiled script?

It does ... can you tell us what the error is and can you show a snippet that has a problem ?

Jos

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for the fast respnse.

Basically the error is caught if I run the script from SciTe, but not when it's compiled. The error is an email error (server not found) that I created just to test.

Ok, the script is large, but here are the related lines: (compiled with 3.2.7.4)

#include "Functions.au3"
Global  $oMyError = ObjEvent("AutoIt.Error", "COMErrFunc"), $oMyRet[2]
.
.
.
make a GUI with a titled window
.
.
.
make a second GUI that has a button that creates the COM error

Functions.au3:

Func COMErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description,3)
    _DoLog("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @CRLF)
    SetError(1); something to check for when this function returns
    Return
EndFunc;==>MyErrFunc

Func _Dolog($text)
    ...some code that logs errors..
EndFunc

see anything wrong? I can PM you the entire code (3100 lines) if you want.

Edited by drlava

Share this post


Link to post
Share on other sites

Sorry,

COM Error with DOM!

err.description is: The transport failed to connect to the server.

err.widescription: (two boxes here, like some unicode out of range)

err.number is: 80020009

err.lastdllerror is: 0

err.scriptline is: -1

err.source is: CDO.Message.1

err.helpfile is:

err.helpcontext is: 0

Share this post


Link to post
Share on other sites

This indicates that the ErrorHandler does work ....

Do you check for @error after com statements to see in the error handler kicked in ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

yes, @error is set, however COMErrFunc() is never called.

When run from SciTe, COMErrFunc() is called and the error popup doesn't happen (preferred in this case).

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

yes, @error is set, however COMErrFunc() is never called.

When run from SciTe, COMErrFunc() is called and the error popup doesn't happen (preferred in this case).

I am confused: Where does the error you posted come from if there is no Error_Handler active ?

One other question: Are there spaces infront of the #include statement ?

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Windows? i don't know, but before I ever learned about COM error handling with AutoIt.Error, a dialog box would appear formatted just like above with the error. This is the default error handling I think, if there is no ObjEvent("AutoIt.Error" specified.

nope no spaces. it goes like this:

;Compiled in Autoit V. 3.2.7.4 Best viewed with SciTE4AutoIt3

;This version: 0.55

$Version='0.55' ;

$TransformVersion='1.33' ;XML transform version

$DTDVersion='1.34' ;XMLTV DTD version

#include <Array.au3>

#include <Date.au3>

#include <string.au3>

#include <GuiTab.au3>

#include <GUIConstants.au3>

#include <File.au3>

#include "Functions.au3"

#include "Functions_XML.au3"

Edited by drlava

Share this post


Link to post
Share on other sites

Windows? i don't know, but before I ever learned about COM error handling with AutoIt.Error, a dialog box would appear formatted just like above with the error. This is the default error handling I think, if there is no ObjEvent("AutoIt.Error" specified.

did you see my EDIT?

One other question: Are there spaces infront of the #include statement ?

There was a bug in an earlier release that included files were missing in compiled script when the line contained leading spaces or tabs..


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

did you see my EDIT?

There was a bug in an earlier release that included files were missing in compiled script when the line contained leading spaces or tabs..

did you see my edit? :)

I know they are being included, becuase other functions are beng called, no problem.

Share this post


Link to post
Share on other sites

Windows? i don't know, but before I ever learned about COM error handling with AutoIt.Error, a dialog box would appear formatted just like above with the error. This is the default error handling I think, if there is no ObjEvent("AutoIt.Error" specified.

nope no spaces. it goes like this:

;Compiled in Autoit V. 3.2.7.4 Best viewed with SciTE4AutoIt3

;This version: 0.55

$Version='0.55' ;

$TransformVersion='1.33' ;XML transform version

$DTDVersion='1.34' ;XMLTV DTD version

#include <Array.au3>

#include <Date.au3>

#include <string.au3>

#include <GuiTab.au3>

#include <GUIConstants.au3>

#include <File.au3>

#include "Functions.au3"

#include "Functions_XML.au3"

Is there anyway you can take the SMTP email portion into a test script and replicate the problem ? (then post the script and include?)

I will be offline in a couple of minutes but will have a look at it tomorrow when nobody else got to it by then...

Jos :)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Is there anyway you can take the SMTP email portion into a test script and replicate the problem ? (then post the script and include?)

I will be offline in a couple of minutes but will have a look at it tomorrow when nobody else got to it by then...

Jos :)

I tried a simple script, even with external includes, but could not replicate. It seems to need the whole program, or at least some unknown part of it.

Share this post


Link to post
Share on other sites

I tried a simple script, even with external includes, but could not replicate. It seems to need the whole program, or at least some unknown part of it.

well PM me the lot and tell me what to do to get it wrong and will try to look at it tomorrow.....

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

ok, thanks. I'll spend a few more minutes here adding a GUI to the test to see if maybe that's the special sauce.

Share this post


Link to post
Share on other sites

Oops, ok one of the UDFs I was using was over-writing

$oMyError wihtout me knowing it,

and it happened in such a way that it would only over-write when run from compiled, so that's why it appeared to be breaking only then.

Now that it's cleared up, things work well. thanks!

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
Sign in to follow this  
Followers 0