Sign in to follow this  
Followers 0

OnAutoItErrorRegister - Handle AutoIt critical errors

35 posts in this topic

Posted (edited)

AutoIt Version: 3.3.6.1+

UDF Version: 1.8

Description: This library allows to register function for AutoIt critical errors.

Usualy it's syntax errors, or array-related errors.

By default the UDF shows custom debug dialog, although it is not possible to perform any real debugging, but we can for example display the error message, restart application, send bug report, or just close the application.

Syntax and parameters:

Syntax:

_OnAutoItErrorRegister ([$sFunction [, $vParams [, $sTitleMsg [, $sErrorMsgFormat [, $bUseStdOutMethod]]]]])

Parameters (all optional):

  • $sFunction

    The name of the user function to call. If this parameter is empty (""), then default (built-in) error message function is called.

  • $vParams

    Parameter(s) that passed to $sFunction (default is "" - no parameters).

  • $sTitleMsg

    The title of the default error message dialog (used only if $sFunction = "").

  • $sErrorMsgFormat

    Formated error message string of the default error message dialog (used only if $sFunction = "").

  • $bUseStdOutMethod

    Defines the method that will be used to catch AutoIt errors (default is True - use StdOut).

Example #1 - Displaying built-in dialog when error is received:

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include "OnAutoItErrorRegister.au3"

_OnAutoItErrorRegister("", "", "My App Error", -1, True)

GUICreate("OnAutoItErrorRegister Example", 350, 200)

GUICtrlCreateLabel("This script is just an example." & @LF & @LF & "It will produce a syntax error in", 25, 40, 300, 50)
GUICtrlCreateLabel("5", 185, 50, 50, 40)
GUICtrlSetColor(-1, 0xF20000)
GUICtrlSetFont(-1, 30, 800, 0, 'Tahoma')
GUICtrlCreateLabel("seconds.", 220, 67, 300, 50)
GUICtrlCreateLabel("The result shown as a CUSTOM error message, you can change it!", 25, 120, 350, 20)
$iUnRegister_Bttn = GUICtrlCreateButton('UnRegister AutoItError handler', 25, 140, 200, 22)
GUICtrlCreateLabel("Copyright jennico, G.Sandler (MrCreatoR) © 2008 - 2011", 25, 170, 350, 80)
GUICtrlSetColor(-1, 0x808080)
GUICtrlSetFont(-1, 8.5, 800, 6)

GUISetState()

Dim $iTimer

For $i = 5 To 1 Step -1
    GUICtrlSetData(4, $i)

    $iTimer = TimerInit()

    While TimerDiff($iTimer) < 1000
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $iUnRegister_Bttn
                _OnAutoItErrorUnRegister()
        EndSwitch
    WEnd
Next

MsgBox(0, "",) ;We deliberately make a syntax mistake (one parameter missing) and call the error!

Example #2 - Call user defined function when recieving error (script restart):

#NoTrayIcon
#include "OnAutoItErrorRegister.au3"

_OnAutoItErrorRegister("_MyErrorHandler");, "", -1, -1, False)

;We deliberately make an array bounding error and call the error!
Dim $aArr[1]
MsgBox(0, "", $aArr[1])

Func _MyErrorHandler() ;Restart the application
    If MsgBox(16+4, 'Crash recieved', 'Restart application?') <> 6 Then
        Return
    EndIf

    Local $sRunLine = @AutoItExe & ' "' & @ScriptFullPath & '"'

    If @Compiled Then
        $sRunLine = @ScriptFullPath
    EndIf

    Run($sRunLine, @ScriptDir)
EndFunc

Attachments:

OnAutoItErrorRegister_1.7.zip

OnAutoItErrorRegister_1.6b.zip

OnAutoItErrorRegister_1.6.zip

OnAutoItErrorRegister.zip

Download: OnAutoItErrorRegister.zip (Counter: Posted Image)

Screenshot:

Posted Image

ChangeLog:

[1.8]

+ Added _OnAutoItErrorUnRegister (see Example 1).

* 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).

[1.7]

* Fixed an issue with showing tray icon even if #NoTrayIcon is specified in the main script.

* Fixed an issue with not passing the original command line parameters to the main script.

Now added /OAER parameter to the command line at the end, it's an identifier for OnAutoItErrorRegister UDF.

[1.6]

* Fixed an issue with COM errors catching (this UDF should not handle COM errors, it was just for sending email function).

* Removed unneccessary #include <File.au3>.

* Fixed bug with auto-ckicked buttons on Windows Vista/7.

v1.5

* Fixed issue with high CPU usage

* "Send bug report" feature improved grately.

* Added ability to translate all UDF elements (titles, messages, buttons and labels) - see "User Variables" section.

* Cosmetic changes to the code.

v 1.4

UDF rewrited.

Initial idea by jennico:

Author(s): G.Sandler (MrCreatoR), jennico

Notes:

  • StdOut method ($bUseStdOutMethod = True) is not compatible with CUI mode.
  • When using "error window catching" method ($bUseStdOutMethod = False), the error window blinks on the screen for a few milliseconds.
  • This UDF executes additional process to monitor for errors, or, if to be more specific, original copy of a process used as a monitor module, and the main script (the code that should be executed) executed as additional process, then initial/original process monitors this copy of process.
  • If you are using _OnAutoItErrorUnRegister when $bUseStdOutMethod = True, then standard AutoIt error message will not be displayed.
  • To use the "Send bug report" feature, there is need to fill related parameters (variables) under the «User Variables» section in UDF file (check the comments of these variables), or just build your own user function.
Edited by MrCreatoR
Sunaj, header127 and JScript like this

Share this post


Link to post
Share on other sites



Posted

Very useful. Thx for sharing. I see your library deals with autoit syntax errors as well as COM errors. I liked the extra functionality like reporting, debugging and restarting.

I took a look at the function _OnAutoItErrorRegister and I wonder if your library will work on compiled scripts in systems where Autoit has not been installed? All my computers have autoit installed, so I can't really test this unless I uninstall autoit.

I've played with the idea of a general COM object error handling function for a while, in an attempt to implement different procedures according to the object that triggered the error. I must have made at least 3 unsatisfactory attempts and have always deferred further development because each time I encountered conflicting issues. That is the main reason why I've not posted anything before, but I'm very interested to see if and how you deal with them.

Regards,

IVAN

Share this post


Link to post
Share on other sites

Posted

I see your library deals with autoit syntax errors as well as COM errors

No no, the COM error handling is for the email sending function. I should move it to the function itself.

To handle COM errors there is ObjEvent, it should be used seperatly for each object.

I wonder if your library will work on compiled scripts in systems where Autoit has not been installed?

Ofcourse it will, i can't see a reason why not.

Share this post


Link to post
Share on other sites

Posted

Updated.

[1.6]

* Fixed an issue with COM errors catching (this UDF should not handle COM errors, it was just for sending email function).

* Removed unneccessary #include <File.au3>.

Share this post


Link to post
Share on other sites

Posted

Another small update:

* Fixed bug with auto-ckicked buttons on Windows Vista/7.

Version not changed.

Share this post


Link to post
Share on other sites

Posted

Sorry, the 1.6 file was not updated, it's called 1.6b now, if anyone has been downloaded 1.6 after i posted my last message, please download the 1.6b again.

Share this post


Link to post
Share on other sites

Posted (edited)

Its really good this, thanks for sharing it. :)

I'm not overly fond of having my email and password in with a script I might pass to someone though, but I suppose its not difficult to create an email just for a certain project.

I've often wondered if there were a viable way of determining the function (if its in one) from where the script crashed.

Anyhow, using your example I tried a number of ways including variables and dllstructs and also enviroment variables, all to no avail.

In the end I tried the console stream, and here the result.

#include <OnAutoItErrorRegister.au3>

Global $a[4]

_OnAutoItErrorRegister("", "", "My App Error")

GUICreate("OnAutoItErrorRegister Example", 350, 200)

GUICtrlCreateLabel("This script is just an example." & @LF & @LF & "It will produce a syntax error in", 25, 40, 300, 50)
GUICtrlCreateLabel("5", 185, 50, 50, 40)
GUICtrlSetColor(-1, 0xF20000)
GUICtrlSetFont(-1, 30, 800, 0, 'Tahoma')
GUICtrlCreateLabel("seconds.", 220, 67, 300, 50)
GUICtrlCreateLabel("The result shown as a CUSTOM error message, you can change it!", 25, 120, 350, 80)
GUICtrlCreateLabel("Copyright jennico, G.Sandler (MrCreatoR) © 2008 - 2011", 25, 170, 350, 80)
GUICtrlSetColor(-1, 0x808080)
GUICtrlSetFont(-1, 8.5, 800, 6)

GUISetState()

For $i = 5 To 1 Step -1
    GUICtrlSetData(4, $i)

    $iTimer = TimerInit()

    While TimerDiff($iTimer) < 1000
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then
            Exit
            ;ExitLoop 2
        EndIf
    WEnd
Next

_1()
_2()
_3()
_1()
_2()
_3()
_1()
_2()
_3()
_4()
_2()
_3()
_1()
_2()
_3()

Func _1()
    ConsoleWrite("_1" & @CRLF)
EndFunc   ;==>_1
Func _2()
    ConsoleWrite("_2" & @CRLF)
EndFunc   ;==>_1
Func _3()
    ConsoleWrite("_3" & @CRLF)
EndFunc   ;==>_1
Func _4()
    ConsoleWrite("_4" & @CRLF)
    MsgBox(0, "", $a[6]) ;We deliberately make an array subscript error! (so it will compile for testing)
EndFunc   ;==>_1

The idea is to consolewrite upon entering each function, the function which errors is the last function used and so we narrow our debugging down. I know there are cons to this, such as extra time in functions etc.. But to me its worth it.

I have a question if someone can answer it.

I tried to use consoleread before the write to remove the last line fron stream, except it did not work, so will this cause memory error/leak.

Also anyone care to donate a regexp :) to get the last function, so it can be added to the 'view bug report'?

EDIT:

the last few functions are seen in the 'send bug report' gui

Edited by JohnOne

Share this post


Link to post
Share on other sites

Posted

I'm not overly fond of having my email and password in with a script I might pass to someone though, but I suppose its not difficult to creat an email just for a certain project.

Me too, but we can encrypt the password :)

I've ofter wondered if there were a viable way of determining the function (if its in one) from where the script crashed.

For that purpose i have AutoItScript Add Debugger.
erm3nda likes this

Share this post


Link to post
Share on other sites

Posted

Thats quite cool that MrCreator.

I've been running it for a few minutes and noticed that the working set memory keeps going up and up, more noticable in your test script when the sleep loop is set to 10.

Very handy for debugging

Yoink !! :)

<puts in box>

Share this post


Link to post
Share on other sites

Posted

Hi there,

I have added this to my script, but when it calls the function "OnAutoItErrorRegister", my script exits without warning, error or reason.

All I did was to add 2 lines to my script:

#include <OnAutoItErrorRegister.au3>

_OnAutoItErrorRegister("", "", "My App Error")

Any ideas as to why this would happen and how to fix it?

Share this post


Link to post
Share on other sites

Posted

All I did was to add 2 lines to my script:

And what about the first example in the first post, is it working?

What AutoIt version you are using?

And also it would be better to see the whole script.

Share this post


Link to post
Share on other sites

Posted

Update...

[1.7]

* Fixed an issue with showing tray icon even if #NoTrayIcon is specified in the main script.

* Fixed an issue with not passing the original command line parameters to the main script.

Now added /OAER parameter to the command line at the end, it's an identifier for OnAutoItErrorRegister UDF.

Share this post


Link to post
Share on other sites

Posted

AutoIt Version: 3.3.6.1

UDF Version: 1.7

Description: This library allows to register function for AutoIt critical errors.

Usualy it's syntax errors, or array-related errors.

By default the UDF shows custom debug dialog, although it is not possible to perform any real debugging, but we can for example display the error message, restart application, send bug report, or just close the application.

Syntax and parameters:

Syntax:

_OnAutoItErrorRegister ([$sFunction [, $vParams [, $sTitleMsg [, $sErrorMsgFormat [, $bUseStdOutMethod]]]]])

.....

if i close my gui then i got an error, application crashed restart now?

Share this post


Link to post
Share on other sites

Posted

The _OnAutoItErrorRegister is incompatible

with this script

If _Singleton("RinominaIncarichi", 1) = 0 Then
MsgBox(0, "Attenzione", "Il Programma è gia in esecuzione")
Exit
EndIf

Why ?

Share this post


Link to post
Share on other sites

Posted

I just want to report this problem. :oops:

The _OnAutoItErrorRegister is incompatible

with this script

If _Singleton("RinominaIncarichi", 1) = 0 Then
MsgBox(0, "Attenzione", "Il Programma è gia in esecuzione")
Exit
EndIf

Why ?

Share this post


Link to post
Share on other sites

Posted (edited)

When I first saw this feature and tested it out it seemed great. There is one big massive problem, it messes up my script. I found that depending on where I placed the function, splashtext/image would double up and not go away. I also found that variables were suddenly not being declared despite the fact that they were being declared on line 1.

I'm sorry, but I cannot use this UDF, until these major glitches are fixed

Edited by subzerostig

Share this post


Link to post
Share on other sites

Posted

I think this is a great function and I've been using it in my recent scripts. I do however have one problem. I want a user input (inputbox) to be above my declaration of onautoiterrorregister so that I can then use that variable. My issue is that this inputbox now opens twice. Is there a way around this?

Thanks!

Share this post


Link to post
Share on other sites

Posted

Hi MrCreatoR,

Cool script! This is something i certainly needed and saved me a bunch of time coding!

One possible bug:

93: Global $sOAER_BugReportSent_Msg = "Please fill all requiered fields"

396: If $iError Then
MsgBox(16, $sOAER_SendBugReport_Title & " - " & $sOAER_Error_Title, _
StringFormat($sOAER_UnableToSend_Msg, $oOAER_ErrorData[0], $oOAER_ErrorData[1]), 0, $hSndBugRprtGUI)
Else
MsgBox(64, $sOAER_SendBugReport_Title & " - " & $sOAER_Success_Title, $sOAER_BugReportSent_Msg, 0, $hSndBugRprtGUI)
401: EndIf

Seems to me like even when successful sending email, it will tell the user to fill all required fields?

Hope that helps and thanks again,

Smerk

Share this post


Link to post
Share on other sites

Posted (edited)

cool

works great

the Idea of Debugging the Script is great.. :)

Is it possible to debug a compiled script | Exe

By maybe

decompiling and substituting the incorrect parameter

with the correct parameter and then again recompiling and replacing the original Exe

I apolizise if i break the rules

Edited by PhoenixXL

Share this post


Link to post
Share on other sites

Posted

I changed the UDF to generate an error report and restart the script error when encountering a problem over there and it worked well but the script is open 2 times how to solve this?

OnAutoItErrorRegister_changed.rar

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