Jump to content

COM Error Handling


Recommended Posts

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....

Link to comment
Share on other sites

  • 1 month later...
  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Developers

you didn't tell me what the error was you got ...

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

Link to comment
Share on other sites

  • Developers

This indicates that the ErrorHandler does work ....

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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"

Edited by drlava
Link to comment
Share on other sites

  • Developers

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..

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

Link to comment
Share on other sites

  • Developers

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 :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

Link to comment
Share on other sites

  • Developers

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.....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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!

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...