Jump to content

Recommended Posts

Posted

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

Posted

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]

Posted

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?

Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (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 (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

i just tried this (doesn't seem to run that last function):

Opt("OnExitFunc", "CaptureSome")

"OnExitFunc" isn't an option according to the helpfile at least.
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
Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (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 (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
Posted

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]

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
×
×
  • Create New...