Sign in to follow this  
Followers 0
gcue

logging errors before a script crashes

12 posts in this topic

is it possible to log errors before a script crashes?

i was looking at debugsetup and filewritelog but it seems you have to tell it where it should be writing to a log so as to predict where the error will occur. kinda tough especially for really long scripts.

is there something like COM ERROR capturing for autoit? can probably be logged there. if not, can anyone think of a way to capture these errors to a log?

thanks

Share this post


Link to post
Share on other sites



is it possible to log errors before a script crashes?

i was looking at debugsetup and filewritelog but it seems you have to tell it where it should be writing to a log so as to predict where the error will occur. kinda tough especially for really long scripts.

is there something like COM ERROR capturing for autoit? can probably be logged there. if not, can anyone think of a way to capture these errors to a log?

thanks

You can use Tools->Trace: Add Trace Lines to add tracers to every line of your script. When you run the script from SciTE, it will write each line as it executes to the console, along with any error codes.


[center][/center]

Share this post


Link to post
Share on other sites

You can use Tools->Trace: Add Trace Lines to add tracers to every line of your script. When you run the script from SciTE, it will write each line as it executes to the console, along with any error codes.

what about a compiled script?

Share this post


Link to post
Share on other sites

Use the trace to find your problem areas and then add your own code for the errors.


[center][/center]

Share this post


Link to post
Share on other sites

what if i did something like this? would it capture any errors (before a crash) then write to the log?

while 1
 if @error then
 _filewritelog($log_file, "an error has occured with line number: " & @scriptlinenumber)
 endif
wend

This won't help you in compiled scripts. According to the help file:

"@ScriptLineNumber - Line number currently being executed. Useful for debug statements specially when a function is called you can pass the caller line number. (Not significant in compiled script)"


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

this was taken from OnAutoitExit function from the helpfile:

Opt("OnExitFunc", "endscript")

MsgBox(0,"","first statement")

Func endscript()

MsgBox(0,"","after last statement " & @EXITMETHOD)

EndFunc

edit: i think i have an older version.. updating---

Edited by gcue

Share this post


Link to post
Share on other sites

OnAutoItStart and OnAutoItExit have been removed in version 3.3.4.0 and replaced by OnAutoItStartRegister, OnAutoItExitRegister and OnAutoItExitUnRegister (introduced with version 3.3.2.0).

What AutoIt version do you use?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

<sorry about that.. i needed to update>

still doesn't seem to give a good clue to investigate the error that caused the crash

here's what the test i am running:

OnAutoItExitRegister("OnAutoItExit")

$ini = @ScriptDir & "\test.ini"

if FileExists($ini) Then
    FileDelete($ini)
EndIf

IniWrite($ini, "section", "key1", "value1")

$section = IniReadSection($ini, "section")

for $x = 1 to 2
    ConsoleWrite($section[$x][0] & @CRLF)
next

FileDelete($ini)

Func OnAutoItExit()
    MsgBox(0,"","script line number: " & @ScriptLineNumber & @crlf & _
    "exitmethod: " & @exitMethod & @crlf & _
    "exit code: " & @exitCode & @crlf & _
    "extended: " & @extended)
EndFunc

results:

script line number: -1

exit method: 0

exit code: 1

extended: 0

Edited by gcue

Share this post


Link to post
Share on other sites

You can't use the script line number on a compiled script! There are no longer "script lines" when the script has been compiled.

You need to investigate your errors (called debugging) and then write your own code to handle them accordingly. You can pass variable information to be sent to the log, etc., but not the line at which the error occurs.

If you have an area with problems, log the error, and when you have it write the log, add the function name (or anything to help you identify it) into your error statement.


[center][/center]

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