gcue 10 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 Share this post Link to post Share on other sites
Affe 1 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] Share this post Link to post Share on other sites
gcue 10 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? Share this post Link to post Share on other sites
Affe 1 Posted May 26, 2010 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
gcue 10 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 Share this post Link to post Share on other sites
jaberwacky 327 Posted May 27, 2010 Look into using OnAutoItExitRegister( "function" ) Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Share this post Link to post Share on other sites
water 2,387 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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
jaberwacky 327 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: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Share this post Link to post Share on other sites
gcue 10 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 Share this post Link to post Share on other sites
water 2,387 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 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
gcue 10 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 Share this post Link to post Share on other sites
Affe 1 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] Share this post Link to post Share on other sites