Jump to content

AutoIt Error Handler and Debugger


jennico
 Share

Recommended Posts

Whenever I include this error handler in my script, I can no longer use "Tools -> Stop Executing" in Scite. Also, my program has a self-updating routine which causes the program to close itself, download updates, then re-open. To close the program, I use ProcessClose but this does not work when the error handler is attached either. Does anybody know why this would be?

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...

@jennico

Your script will run 2 program at the same time right?

Is there any possibility to get only 1 program running if I'm using this UDF?

Thanks 4sharing...

Yes, I found this and tried to kill the first process with Processclose. And then it turns out not work if I did this.

I don't quite understanding this, and does this two processes run the the same functions at the same time?

Looking forward to hear some explanation, thanks!

Link to comment
Share on other sites

  • 1 month later...

jenico, thanks for the code, i am using it .

one small thing i wanted to mention. being a newbie to this forum, i can tell from experience about the oversight error which could happen to others as well. i noticed in many a thread , the latest versions were attached to the first post, of course happenings around to be monitored in the last post. pls can u attach ur latest file to the first post it will be very comfortable for a new comer thanks a lot

(i have posted a bit of modification can u have a look at it and comment, thanks)

Link to comment
Share on other sites

  • 1 year later...

Hi,

Nice piece of work, Iv been looking for something that gives "better" info to the end user when/if a compiled script crashes and was hoping this would be it.

Iv tested it with un-compiled scripts and it works fine however when i tested it with a compiled script it does not give the line number of the problem ? using the original ver it said error line 1 (as AI always does) and in one of the edited versions ( MrCreatoR's i think) it says "Error Line N/A" and the errors descriptions are not right either.

Could someone point me in the right direction , what am i missing ? is it something im not doing right when compiling it?

Iv also read that you cant ProcessClose() your script either, if thats correct then i couldn't use it anyhow.

Is there no way to get even just the line number of a crashed compiled script?

Thx all.

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
Share on other sites

  • 2 months later...

Is this UDF still working with the latest non-beta version of autoit? when using the example it loops through the button function calls telling me the line number of the error over and over and over never letting me click on any of other buttons such as send error report. its like its doing the GUIGetMsg() and thinking I am pressing the button when im not.

tried it compiled and with a single line error with the include of the _ErrorHandler.au3

~MC

Link to comment
Share on other sites

Very nice. This is awesome. However, when you attempt to change something in the Debug button, error.

A:\AutoIt\AutoIt3\Include\_ErrorHandler.au3 (136) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$t[$number] = StringReplace($t[$number], StringTrimRight($a[2], 1), $x)
^ ERROR

EDIT: Nevermind. Seems to be fixed now?

Edited by Skrip

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Hi

loving this thread i think it will help my program loads thanks. I have as suggestion and also a small request for help. My program can run currently on xp, vista and 7 which is good. i primarily use 7 but a few friends use other OS's and have occasionally come accross errors and not been able to tell me what they were (which is where this script comes in :-) ) i think it would be good if the error message in the email sent some other info such as the error in question, the OS, the RAM and CPU and service pack. I can write that in myself but was just making a sugegstion there.

The small request for help is this. My program has lots of checkboxes. some called checkbox 1, 2, 3 etc... and some renamed totally e.g the name of the program to run. I was wondering if anyone had some code that would (at the time of compiling the email) be able to list which checkboxes are curerntly checked. I admit this could be done by manually checking each box but thats tons of code. Any ideas?

thanks

Drunken Frat-Boy Monkey Garbage

Link to comment
Share on other sites

  • 4 months later...

Hey there!

I've added InetMail to the UDF so I can send the bug report to my email address.

I have a problem though with the variable $sErrDesc. If I put everything in the body except for this line, it works fine. But the moment I add the $sErrDesc, it gives me this message:

"The command line argument is not valid. Verify the switch you are using."

I've added >>>>>>>>>>>>>>>>>>>>>>>> to the line I have a problem with.

PS: I have changed the look slightly for my own use.

#NoTrayIcon
#include-once
#include <StaticConstants.au3>
#include <INet.au3>

_AutoItErrorHandler()

Func _AutoItErrorHandler($sTitleMsg = -1, $sErrorMsgFormat = -1)

    If StringInStr($CmdLineRaw, "/AutoIt3ExecuteScript") Then
        Opt("TrayIconHide", 0)
        Return
    EndIf

    Local $sErrorMsg = ""
    Local $hErrGUI, $nMsg, $SendReport_Label, $SendReport_Icon, $ShowBugReport_Label, $ShowBugReport_Icon
    Local $ContinueApp_Label, $ContinueApp_Icon, $RestartApp_Label, $RestartApp_Icon, $CloseApp_Label, $CloseApp_Icon
    Local $sRunLine = @AutoItExe & ' /ErrorStdOut /AutoIt3ExecuteScript "' & @ScriptFullPath & '"'

    Local $iPID = Run($sRunLine, @ScriptDir, 0, 2 + 4)
    ProcessWait($iPID)

    While 1
        $sErrorMsg &= StdoutRead($iPID)
        If @error Then ExitLoop

        Sleep(10)
    WEnd

    If $sErrorMsg = "" Then Exit
    If Not IsString($sTitleMsg) Then $sTitleMsg = "RapidStudio Error Message"
    If Not IsString($sErrorMsgFormat) Then $sErrorMsgFormat = "Program has been Terminated :(.\r\n" & _
            "Please report about this bug to the author, sorry for the inconvenience!\r\n\r\n" & _
            "Program Path: %s\r\n\r\nError Line: %s\r\n\r\nError Description: %s"



    Local $labelbgW = 131, $labelbgH = 22, $labelbgT = 34 + 50, $labelbgColor = 0xFFFFFF, $labelbgColor2 = 0x999999
    Local $labelW = 115, $labelH = 15, $labelT = $labelbgT + 4
    Local $iconW = 16, $iconH = 16, $iconT = $labelbgT + 3
    Local $g = 15
    Local $label1L = $g + 17, $label2L = $label1L + $labelbgW + $g, $label3L = $label2L + $labelbgW + $g, $label4L = $label3L + $labelbgW + $g
    Local $labelbg1L = $g, $labelbg2L = $labelbg1L + $labelbgW + $g, $labelbg3L = $labelbg2L + $labelbgW + $g, $labelbg4L = $labelbg3L + $labelbgW + $g
    Local $icon1L = $g + 3, $icon2L = $icon1L + $labelbgW + $g, $icon3L = $icon2L + $labelbgW + $g, $icon4L = $icon3L + $labelbgW + $g




    $hErrGUI = GUICreate($sTitleMsg, $labelbg4L + $labelbgW + $g, 120, -1, -1, -2134376448) ;BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
    WinSetOnTop($hErrGUI, "", 1)
    GUISetIcon("User32.dll", -1)
    GUICtrlCreateIcon("user32.dll", 103, 11, 11, 32, 32)
    GUICtrlSetBkColor(GUICtrlCreateLabel('An error occurred in the application.  First try to "Restart" the application.' & @CRLF & 'If the problem persists, please contact support.', 52, 22, 518, 30), -2)
    #Region Label 1
    $RestartApp_Frame = GUICtrlCreateLabel("", $labelbg1L - 1, $labelbgT - 1, $labelbgW + 2, $labelbgH + 2, $SS_BLACKFRAME)
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetBkColor(GUICtrlCreateLabel("", $labelbg1L, $labelbgT, $labelbgW, $labelbgH), $labelbgColor2)
    GUICtrlSetState(-1, 128)
    $RestartApp_Label = GUICtrlCreateLabel("    Restart application", $label1L, $labelT, $labelW, $labelH)
    GUICtrlSetBkColor(-1, -2)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetCursor(-1, 0)
    $RestartApp_Icon = GUICtrlCreateIcon("shell32.dll", 255, $icon1L, $iconT, 16, 16)
    GUICtrlSetCursor(-1, 0)
    #EndRegion Label 1
    #Region Label 2
    $CloseApp_Frame = GUICtrlCreateLabel("", $labelbg2L - 1, $labelbgT - 1, $labelbgW + 2, $labelbgH + 2, $SS_BLACKFRAME)
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetBkColor(GUICtrlCreateLabel("", $labelbg2L, $labelbgT, $labelbgW, $labelbgH), $labelbgColor)
    GUICtrlSetState(-1, 128)
    $CloseApp_Label = GUICtrlCreateLabel("     Close application", $label2L, $labelT, $labelW, $labelH)
    GUICtrlSetBkColor(-1, -2)
    GUICtrlSetCursor(-1, 0)
    $CloseApp_Icon = GUICtrlCreateIcon("shell32.dll", 240, $icon2L, $iconT, 16, 16)
    GUICtrlSetCursor(-1, 0)
    #EndRegion Label 2
    #Region Label 3
    $SendReport_Frame = GUICtrlCreateLabel("", $labelbg3L - 1, $labelbgT - 1, $labelbgW + 2, $labelbgH + 2, $SS_BLACKFRAME)
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetBkColor(GUICtrlCreateLabel("", $labelbg3L, $labelbgT, $labelbgW, $labelbgH), $labelbgColor)
    GUICtrlSetState(-1, 128)
    $SendReport_Label = GUICtrlCreateLabel("   Send bug report", $label3L, $labelT, $labelW, $labelH)
    GUICtrlSetBkColor(-1, -2)
    GUICtrlSetCursor(-1, 0)
    $SendReport_Icon = GUICtrlCreateIcon("shell32.dll", -157, $icon3L, $iconT, 16, 16)
    GUICtrlSetCursor(-1, 0)
    #EndRegion Label 3
    #Region Label 4
    $ShowBugReport_Frame = GUICtrlCreateLabel("", $labelbg4L - 1, $labelbgT - 1, $labelbgW + 2, $labelbgH + 2, $SS_BLACKFRAME)
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetBkColor(GUICtrlCreateLabel("", $labelbg4L, $labelbgT, $labelbgW, $labelbgH), $labelbgColor)
    GUICtrlSetState(-1, 128)
    $ShowBugReport_Label = GUICtrlCreateLabel("   Show bug report", $label4L, $labelT, $labelW, $labelH)
    GUICtrlSetBkColor(-1, -2)
    GUICtrlSetCursor(-1, 0)
    $ShowBugReport_Icon = GUICtrlCreateIcon("shell32.dll", 23, $icon4L, $iconT, 16, 16)
    GUICtrlSetCursor(-1, 0)
    #EndRegion Label 4

    DllCall("user32.dll", "int", "MessageBeep", "int", 0x00000010)
    GUISetState()

    While 1
        $nMsg = GUIGetMsg()

        Switch $nMsg
            Case $SendReport_Label, $SendReport_Icon, $SendReport_Frame
                $sErrorMsgFormat = "Program has been Terminated :(.\r\n" & _
                        "\r\n\r\n" & _
                        "Program Path: %s\r\n\r\nError Line: %s\r\n\r\n" & _
                        "Error Description: %s\r\n\r\n"

                $sScriptPath = StringRegExpReplace($sErrorMsg, "(?s)\A(.*) \(\d+\) : ==> .*", "\1")
                $iScriptLine = StringRegExpReplace($sErrorMsg, "(?s)\A.* \((\d+)\) : ==> .*", "\1")
                $sErrDesc = StringRegExpReplace($sErrorMsg, "(?s)\A.* \(\d+\) : ==> (.*)", "\1")

                If @Compiled Then
                    $sScriptPath = @ScriptFullPath
                    ;$iScriptLine = "N/A"
                    $sErrDesc = StringRegExpReplace($sErrorMsg, '(?s).*: ==> (.*):', '\1')
                EndIf
                $Address = 'joesoap@email.com'
                $Subject = 'RS Bug Report: Install Downloader'
                $bodyline1 = "Program has been Terminated :(."
                $bodyline2 = "Program Path: " & $sScriptPath
                $bodyline3 = "Error Line: " & $iScriptLine
                $bodyline4 = "Error Description: " & $sErrDesc    ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Problem!!!! "The command line argument is not valid.  Verify the switch you are using."
                _INetMail($Address, $Subject, $bodyline1 & @crlf & $bodyline2 & @CRLF & $bodyline3 & @CRLF & $bodyline4)
;~              MsgBox(262144 + 64, "Send Bug Report", "Here we can sent an Email with the bug report!", 0, $hErrGUI)
            Case $ShowBugReport_Label, $ShowBugReport_Icon, $ShowBugReport_Frame
                $sScriptPath = StringRegExpReplace($sErrorMsg, "(?s)\A(.*) \(\d+\) : ==> .*", "\1")
                $iScriptLine = StringRegExpReplace($sErrorMsg, "(?s)\A.* \((\d+)\) : ==> .*", "\1")
                $sErrDesc = StringRegExpReplace($sErrorMsg, "(?s)\A.* \(\d+\) : ==> (.*)", "\1")

                If @Compiled Then
                    $sScriptPath = @ScriptFullPath
                    ;$iScriptLine = "N/A"
                    $sErrDesc = StringRegExpReplace($sErrorMsg, '(?s).*: ==> (.*):', '\1')
                EndIf

                MsgBox(262144 + 4096, $sTitleMsg, StringFormat($sErrorMsgFormat, $sScriptPath, $iScriptLine, $sErrDesc), 0, $hErrGUI)
            Case $RestartApp_Label, $RestartApp_Icon, $RestartApp_Frame
                $sRunLine = @AutoItExe & ' "' & @ScriptFullPath & '"'
                If @Compiled Then $sRunLine = @ScriptFullPath

                Run($sRunLine, @ScriptDir)

                Exit
            Case $CloseApp_Label, $CloseApp_Icon, $CloseApp_Frame, -3
                Exit
        EndSwitch
    WEnd

    Exit

EndFunc   ;==>_AutoItErrorHandler
Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...

I doubt you will read it, but for anybody else:

Descriptions may contain spaces, and if stuff is used as a commandline argument 'you need to surround space containing messages with quotes to make them being accepted as one parameter', perhaps even filter out new-line characters etc. ;)

Hey there!

I have a problem though with the variable $sErrDesc. If I put everything in the body except for this line, it works fine. But the moment I add the $sErrDesc, it gives me this message:
"The command line argument is not valid. Verify the switch you are using."
I've added >>>>>>>>>>>>>>>>>>>>>>>> to the line I have a problem with.

Link to comment
Share on other sites

  • 6 months later...

Has anyone gotten any of these versions to work when compiled?

I'm having trouble getting any one of these version to work when I compile it with the latest AutoIt or the latest beta ver.

AutoIt ver. 3.3.10.2

AutoIt beta ver. 3.3.11.3

If you have could you please post the latest version you have working?

Thank you,

Docfxit

Link to comment
Share on other sites

  • 6 years later...
  • 2 years 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...