gcue Posted May 26, 2010 Posted May 26, 2010 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
Affe Posted May 26, 2010 Posted May 26, 2010 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?thanksYou 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]
gcue Posted May 26, 2010 Author Posted May 26, 2010 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?
Affe Posted May 26, 2010 Posted May 26, 2010 Use the trace to find your problem areas and then add your own code for the errors. [center][/center]
gcue Posted May 27, 2010 Author Posted May 27, 2010 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
jaberwacky Posted May 27, 2010 Posted May 27, 2010 Look into using OnAutoItExitRegister( "function" ) Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
water Posted May 27, 2010 Posted May 27, 2010 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
jaberwacky Posted May 27, 2010 Posted May 27, 2010 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. Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
gcue Posted May 27, 2010 Author Posted May 27, 2010 (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)EndFuncedit: i think i have an older version.. updating--- Edited May 27, 2010 by gcue
water Posted May 27, 2010 Posted May 27, 2010 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
gcue Posted May 27, 2010 Author Posted May 27, 2010 (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 May 27, 2010 by gcue
Affe Posted May 27, 2010 Posted May 27, 2010 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]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now