Jump to content

Stop fatal errors from crashing script run


Recommended Posts

Hello,

I hope someone can help me with my urgent Problem. I want to stop "fatal" autoit Errors from crashing my script run, like assigning a value to a non existent browser DOM item. I could not find a matching thread by search. Only the General recommendation to check the com object before doing an Operation. Unfortunately, that is not a save solution, because the Website works in such a way that clicks on links open extra Windows to enter Information, after entering it is sent by Ajax call to a servlet and the result is used to manipulate the Website in place! Hence, it makes Little sense to check if an element exists before accessing it, because it can be there at check time but already cut out at the time I try to assign a value to a Sub part. I can also not check if anything has changed, because the Content does not always Change.

So, is there any good Approach? I guess it is still not possible to catch all fatal autoit Errors, occurring in a small part of the Code?

Thanks,

Michael

PS: wrong capitalization Comes from Auto correction and I don't now how to Switch it off, sorry.

 

 

Link to post
Share on other sites

Please have a look at ObjEvent in the help file. There you will find an example how to handle COM errors (like assigning a value to a non existent browser DOM item ).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Hello all,

thanks a lot for your quick Responses!!

@Somerset: I cannot post the script here, because it contains corporate data. And apart from that, I don't think that real Code would make much sense, because the Errors happen at very different places. In pseudo/example Code it is something like this

Func example()Local $oIE = _IEAttach("Website title")

If @error Then

Link to post
Share on other sites
Hello all,

thanks a lot for your quick Responses!!
 
Since weeks, I very deeply read into and worked with the topic and use ObjEvent and custom handlers in many different approaches. As a result, I tried to express my initial question very carefully and to point out that simply catching COM errors with ObjEvent and a registered callback alone will not do the trick. :-(
 
The question is: How to avoid fatal AUTOIT errors from crashing the script run, in an environment that does NOT allow to ensure the COM object will still be available at the time of assignment (because the asynchronous callback may strike just after checking the old DOM element). Is it possible in the newest version, at all? Or is AutoIt the wrong program for the Job?
 
@Somerset: I cannot post the script here, because it contains corporate data. And apart from that, I don't think that real Code (all 1500 lines?) would make much sense, because the Errors occur at very different places and only sometimes (not reproducible). In pseudo/example Code it is something like this
Quote

 

_IEErrorHandlerRegister()
If Not (example()) Then
  Msgbox(0, "", "Action not finished")
  Exit 0
EndIf
exit 0
 
Func example()
  Local $oIE = _IEAttach("Website title")
  If @error Then Return False
  $oIE.document.getElementsByName("myelem")(2).value
  If @error Then Return False
  $oIE.document.getElementsByName("myelem")(2).value = "done"
  Return True
EndFunc

 

 

Sometimes this code would end with a fatal error in the assignment line of the element (example's line 5), but most times it runs through.
Until recently, in example's line 3 I did like
Quote

IsObj($oIE.document.getElementsByName("myelem")(2))
If @error Then Return False

But the @error was always 0. I found out that the reason is IsObj, which is an AutoIt function that resets the error macro. So I stepped down to having AutoIt just trying to access the object and I can then catch the COM error from the IE.au3 standard handler.

Regards,
Michael
Link to post
Share on other sites
2 minutes ago, Earthshine said:

with no testable script, good luck getting the right help

This shall not Sound unpolite: I think I have condensed the non-reproducible error quite well. I don't know what Code I should post and how it would help you. Maybe the just posted example Code can Show what I mean?

The Problem there Comes at the assignment of "done" to a non existing DOM element (example function's line 5). It says that the attribute or method of the com object does not exist. How can I stop this error from stopping the run?

Link to post
Share on other sites

Which version of AutoIt do you run? There is a bug in AutoIt after 3.3.12.0 where nested COM operations that result in an error crash the script.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

As described here:

This crashes the script:

$aResult[$iIndex][1] = $oTemp.Name.Name

This works just fine:

$oTemp = $oMatch.Name
If Not @error Then $aResult[$iIndex][1] = $oTemp.Name

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites
5 minutes ago, farouk12 said:

I don't have IE,

but try to use Execute func in the before " If @error Then Return False "

like

Execute("$oIE.document.getElementsByName("myelem")[2]")
if @error then exit 0

 

Thank you farouk. Ok, but how can this help to assure the assignment? Also without Execute, at least These two lines work well. If the element is not available, a com error is throught, that is caught in the second line and the function ist left with False. If the Elements exists, we proceed to the assignment, where the element may just be cut.

In General, I would like to avoid eval() and execute(), if possible. But I will use it if it's a working Workaround.

 

Link to post
Share on other sites
21 minutes ago, water said:

As described here:

This crashes the script:

$aResult[$iIndex][1] = $oTemp.Name.Name

This works just fine:

$oTemp = $oMatch.Name
If Not @error Then $aResult[$iIndex][1] = $oTemp.Name

I use Version 3.3.14.2

Sorry, "Crash" was not the best word in this context. It is an AutoIt error that stops the script run. With info that the metod cannot be used with the obj. Although it was validated just before.

In fact, apart from that, also the whole script crashes after running for some time, with just a popup window that the script stopped working and was closed.

Link to post
Share on other sites
17 minutes ago, farouk12 said:

Mostly it execute expression (Like Execute("$F"))

if it find error ( Variable not declared ). it return a non zero @error rather then crashing the script. 

Ok. This line does not stop the script. It stops at the assignment.

But I have just tried it and  YESS, it Looks like this is the solution!!! At least a Workaround! The com error is thrown, but not the AutoIt fatal that stops the execution:

Quote

Execute("$oIE.document.getEleeojfdljfldf('myelem')[2]") 

ConsoleWrite(@error)

Just prints 1.

Thanks a lot! :-))))))))

 

Link to post
Share on other sites
22 hours ago, farouk12 said:

Mostly it execute expression (Like Execute("$F"))

if it find error ( Variable not declared ). it return a non zero @error rather then crashing the script. 

Don't know if I should open a new thread.

I have tried to replace the direct calls in my Code by Execute("<Code>"), which works for most cases, but not with assignment to the COM Attribute.

Quote

$oIE.document.location.href = 'http://www.leo.org'        ;; @error = 0 and site is correctly loaded

Execute("$oIE.document.location.href = 'http://www.leo.org'")  ;; @error = 0, but site is not loaded

Execute("oIE.document.location.href = 'http://www.leo.org'")  ;; @error = 1, site not loaded

Assign("$oIE.document.location.href", "'http://www.leo.org'")  ;; @error = 1, site not loaded

Assign("oIE.document.location.href", "'http://www.leo.org'")  ;; @error = 1, site not loaded

Assign("$oIE.document.location.href", "http://www.leo.org")  ;; @error = 1, site not loaded

Assign("oIE.document.location.href", "http://www.leo.org")  ;; @error = 1, site not loaded

Do I do something wrong? How can I call this assinment in a fatal-error-save way, too?

BR

Michael

 

Link to post
Share on other sites

NOTE: That was an EXAMPLE for an assignment. I know that I can use _IENavigate to change the site.

As example, I could as well have used $oIE.document.title = 'new title'. The question Points at how to make an assignment to a com object, not at navigating to another site.

Thanks

Link to post
Share on other sites

I get a litle bit confused by this thread and I fear the goal gets out of sight :(

To sum it up:

  • An Autoit script can only handle exceptions in the scope of the script.
  • COM related exceptions can be handled AFTER they happened by a COM error handler. No need to check objecs in advance.
  • Fatal errors crashing a script can NOT be handled by AutoIt
  • A reproducer script (as small as possible) would greatly help.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...