Jump to content

OnAutoItErrorRegister - Handle AutoIt critical errors


MrCreatoR
 Share

Recommended Posts

Real nice function to handle exceptions. Using 3.3.8.1 I ran into some issues.

1) I have the option must declare on true and had some errors (variable used without being declared):

$aCursorInfo, $sScriptPath, $iScriptLine, $sErrDesc

2) Though I use 1.7 (with the /OAER parameter) I still get unexpected number of parameters. When starting without setting parameters I get uncompiled 3 parameters and compiled 1 parameter. Can't these cli parameters be removed from the cmdLine array after registering by for example_arraySearch/_arrayDelete? (The problem with removing items is that cmdLine is a constant...)

3) I also would suggest that _OnAutoItErrorRegister would be split in two (developer visible) functions:

a. _OnAutoItErrorRegister([$sFunction = "" [, $vParams = "" [, $defaultCrashReporter = -1 [, $sErrorMsgFormat = -1 [, $bUseStdOutMethod = True]]]]])

b. _OnAutoItErrorReporter("Title","Mail Addres","Mail Server","Mail Server Port"[,"SSL"])

This has two advances. The developer don't need to change the UDF file to configure the reporter and a custom function can be used together with the default reporter (For example, before starting the reporter the database can be closed or a temp directory be deleted).

4) _OnAutoItErrorUnRegister would be also nice

Edited by skin27
Link to comment
Share on other sites

  • 4 weeks later...

1) I have the option must declare on true and had some errors (variable used without being declared)

Will fix it.

2) Though I use 1.7 (with the /OAER parameter) I still get unexpected number of parameters. When starting without setting parameters I get uncompiled 3 parameters and compiled 1 parameter. Can't these cli parameters be removed from the cmdLine array after registering by for example_arraySearch/_arrayDelete? (The problem with removing items is that cmdLine is a constant...)

I will try to remove the usage of command line for the second run detection.

This has two advances. The developer don't need to change the UDF file to configure the reporter and a custom function can be used together with the default reporter (For example, before starting the reporter the database can be closed or a temp directory be deleted).

You can do this already, just set the $sFunction parameter to your function (see Example 2).

4) _OnAutoItErrorUnRegister would be also nice

Will add it.

Thanks for the suggestions.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Update...

[1.8]

+ Added _OnAutoItErrorUnRegister (see Example 1). Note: If you are using _OnAutoItErrorUnRegister when $bUseStdOutMethod = True, then standard AutoIt error message will not be displayed.

* Removed the usage of command line to detect second script run.

* More stability in detecting AutoIt error message (when $bUseStdOutMethod = False).

* Fixed issue when main script (or other UDF) uses Opt('MustDeclareVars', 1).

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 3 months later...

Hello!

Seems like a great UDF; I'm gonna test it tomorrow..

Just a question:

How does the UDF affect my script regarding performance and resources allocations? I read that the UDF will start two instances of the actual AutoIt process (program).

Does this mean that my script may run slower, or use more server resources? For example, my program currently use ~60% of CPU power and ~600 Mb RAM without UDF - will my script run slower, or use ~1.2 Gb RAM with the UDF?

Thanks,

Edited by Xibalba
Link to comment
Share on other sites

  • 8 months later...

Thank you for this very useful udf!

but your udf have few problems and i also have a new idea about the second process.

first, i will start with your bugs:

Bugs:

Bug 1:

1) Use the code below:

#include <Array.au3>
#include <OnAutoItErrorRegister.au3>
_OnAutoItErrorRegister()


If $CmdLine[0] > 0 Then
    _ArrayDisplay($CmdLine,"the parameters")
Else
    MsgBox(0,"","no parameters")
EndIf

2) compile the script

3) run the exe file with this parameter for example:

"parm1 parm2 parm3"

the ( " ) is very important to write for the bug.

The result you will get:

ilg35u.jpg

This Should NOT be the result!

the result should be this:

2h5qoht.jpg

this is because string

parm1 parm2 parm3

is between the ( " ) signal.

i have fixed the bug by changing in lines 171 and 148 the line:

$sRunLine &= ' ' & $CmdLine[$i]

to

$sRunLine &= ' ' & '"' & $CmdLine[$i] & '"'

this solved the problem.

 

Suggestions:

1) It would be good if I could choose the name of the second process which is loaded with script.

for example i want that the name of the second process will be: "my script name - bug reporter.exe" and the first process will be "my script name.exe"

This way it looks much better!

Edited by Guest
Link to comment
Share on other sites

  • 1 month later...

Seems it have conflict with my self-update function, the .exe process did't exit after run(), the will be two same name exe process when add OnAutoItErrorRegister....

Func _Self_Update($newfile,$oldfile)
    Local $newfile_time=Number(FileGetTime($newfile,0,1))
    Local $oldfile_time=Number(FileGetTime($oldfile,0,1))
    Local $newfile_ver=FileGetVersion($newfile)
    Local $oldfile_ver=FileGetVersion($oldfile)
    Local $newfile_cp=FileGetShortName($newfile)
    Local $oldfile_cp=FileGetShortName($oldfile)
    If FileExists($newfile) And $newfile_time > $oldfile_time Then
        Local $if_update = MsgBox(1,"Auto-Update", StringReplace($exe_file_name,".exe","") & @CRLF & @CRLF & "New version available, please click OK to update!" & @CRLF & _
        @CRLF & "Current version: " & @TAB & $oldfile_ver & _
        @CRLF & "New version:" & @TAB & $newfile_ver )
        If $if_update = 2 Then Return
            FileDelete(@TempDir & 'rst.bat')
            FileWrite(@TempDir & 'rst.bat', 'ping 127.0.0.1 >nul' & @CRLF _
                                & 'copy /y ' &$newfile_cp &' ' & $oldfile_cp & @CRLF _
                                & $oldfile_cp & @CRLF _
                                & 'echo by pcbar')
            Run(@TempDir & 'rst.bat', "", @SW_HIDE)
            Exit
    EndIf
EndFunc

Link to comment
Share on other sites

  • 2 weeks later...

Does this work with autoit 3.3.10.0? If I run either of the examples.au3 files it works, however if I compile the example the script does nothing yet the example process .exe is still running and taskmanager shows cpu is doing something with that process.

I have a ton of compiled scripts I would love to package this with.

~GD

Link to comment
Share on other sites

  • 1 month later...

I have not had time to try fixing the problem, but it looks like the defect is in this function.  If you place a msgbox in here it loops forever, so it looks like it cannot grab a proper value for WinGetProcess?

It looks like there are a lot of changes in this release, so I have not analysized all of them.  Also, it seems like scripts run fine if ran from the editor vs. compiled.

 

Func __OnAutoItErrorRegister_WinGetHandleByPID($iPID, $sTitle = '[CLASS:AutoIt v3]')
Local $aWinList = WinList($sTitle)
 
For $i = 1 To UBound($aWinList)-1
;Hidden and belong to process in $iPID
If Not BitAND(WinGetState($aWinList[$i][1]), 2) And WinGetProcess($aWinList[$i][1]) = $iPID Then
Return $aWinList[$i][1]
EndIf
Next
 
Return 0
EndFunc
Link to comment
Share on other sites

  • 4 weeks later...

Hey!! Thanks for awesome job!!!! It is very useful for me

I've reworked it a bit for myself: 

in Func _OnAutoItErrorRegister I've made this ( line 204 )

If $sErrorMsg = "" Then
Exit
Else
Local $ErrorLogfile = @ScriptDir & "\Autoit_Error_Handlings.txt"
Local $file = FileOpen ($ErrorLogfile, 1)
FileWrite($File, StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC) & " " & $sErrorMsg & @CRLF & @CRLF)
EndIf

So for I am interested in this file as developer. Also we can e-mail this whole file to developer instead of only error description.

Cya :)

Link to comment
Share on other sites

  • 3 months later...

I see many subVersions of the main UDF described here.

Can anyone point me for the correct one? (the less buggy)

Just wanna a way to retry app when suddently breaks (it does too much times, more than expected)
I read about TryCatch blocks on that forum but didn't solve my problems.

Thank you

Edited by erm3nda

~ SELF SIGNED ~

How much warning points do i need to get my free spicy hammon?

Link to comment
Share on other sites

I'd try to add _OnAutoItErrorRegister() on my script and now is not working.

The au3 file is running without changes, and the OnAutoIt runs properly. 

The compiled one just starts and freezes with no tray. 

how can i break the compiled script just by add one more function on it's default way?
​I'm stucked just on the AutoIT error handling :(

Regards.

~ SELF SIGNED ~

How much warning points do i need to get my free spicy hammon?

Link to comment
Share on other sites

  • 4 weeks later...

Seems nice uncompiled

I don't see why when you run my app, and it crashes, you need my email password to send me a debug report.

Trying to Build my app drives my anitvirus (AVG) crazy and I can no longer BUILD with #include "OnAutoItErrorRegister.au3"

 
I didn't even make any other modifications, just added the include.
 
Removed #include, and AVG still goin Nutz, hope a restart will fix it.
 
EDIT: Restart = Nope, Now i'm Screwed :)
Edited by LeCarre
Link to comment
Share on other sites

  • 1 year later...

Update...

v1.9
+ Added error line detection for compiled script (to display actual line which caused the error).
    Script must be executed before compilation (after any change in it), or use '#AutoIt3Wrapper_Run_Before=%autoitdir%\AutoIt3.exe "%in%" /BC_Strip' in your main script.
    !!! Do NOT use Au3Stripper when compiling the main script.
+ Added second function call detection (to prevent multiple recursive execution).
* Fixed command line issue.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Update...

 

v2.0
* UDF rewritten (used methods from AutoItErrorTrap UDF).
  - Syntax changed, check function header for details.
* Dropped AutoIt 3.3.8.1 support.
+ Added last window screen capture feature. File can be sent as attachment when using "Send Bug Report" feature.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 3 weeks later...

Thx, Mr Creator.

There's a little bug though... the "To" word has become a reserved word in AutoItv3 as of version 3.3.12.0 (https://www.autoitscript.com/trac/autoit/ticket/2768)
Think it will be a little challenge to fix this one as you're using the CDO.Message COM object directly. Don't know whether there are aliases of some kind to work around this issue.

Edit: Think you have to revise your CDO.Message function to use the Recipient property or Recipients collection object instead.

Edited by hvandrie
Link to comment
Share on other sites

Just use AutoIt 3.3.14.2

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • 9 months later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...