Jump to content

trap autoit errors to function ?


jennico
 Share

Recommended Posts

hi there,

i would like to have the possibility to trap any autoit error (not com error) and lead it to an individual function where i can decide what to do now (maybe restart the script...).

the autoit built in error box ("error in line -1") is a little bit ... ambarassing when you publish an autoit built exe. i would prefer an individual error message.

is it possible by now ?

( i thought about a program launcher which starts the exe with "run" as a child process and reads the standard_i/o_flag stream, but i am not sure if that would catch the error ? )

anyone tried something like that before ?

regards

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

That might be a very difficult thing to implement - think about that most of AutoIt commands can set the @error flag and those who doesn't, can fail due to some incorrect parameter.

Adding an error check after every command it's not an option - it will double (at least) your script's length and the error handling function can become huge.

StdErr might provide a solution but I'm not an expert in working with.

Good luck,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

maybe it's a feature request, but why not implement an option "onAutoitError('myerrorfunc')" at least for compiled scripts and put the detailed kind of error in a macro ?

That could look a lot more professional then, no ? and one could write the error to a log file if necessary.

regards j.

(once ago i had an autoit program online that happened to crash on certain computers and on others it went fine. Since the users only had the standard autoit "line -1" message, it took me two weeks to isolate the error that was only related to french and spanish codepages and for myself by no means reproductable.)

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

well, i got it !

the stderror or stdread stream does not work. but i found a different way:

;#=#INDEX#==================================================================#
;#  Title .........: AutoIt3 Error Handler                                  #
;#  Date ..........: 4.9.08                                                 #
;#  Author ........: jennico (jennicoattminusonlinedotde)                   #
;#==========================================================================#

;############################################################################
;   1st part (launcher) copy in first line of your program
;############################################################################
#region;-------launcher
If StringInStr($cmdlineraw,"*")=0 Then
    Opt("TrayIconHide",1)
    If @Compiled Then
        $x=Run(@ScriptName&" *")
    Else
    ;   $x=Run("Autoit3.exe "&@ScriptFullPath&" *")
        $x=Run('"Autoit3.exe" "'&@ScriptFullPath&'" *')
    EndIf
    ProcessWait($x,5)
    While ProcessExists($x)
        If WinActive("AutoIt Error") Then _OnAutoItError(WinGetText("AutoIt Error"))
        Sleep(20)
    WEnd
    Exit
EndIf
#endregion;-------launcher
;############################################################################
;   end 1st part (launcher) now comes your program
;############################################################################






#region;-------------user script start

GUICreate(" AutoIt Error Handler Example Script  ©  2008 by jennico")
    GUICtrlCreateLabel("This script is just an example."&@CRLF&@CRLF& _
        "It will produce a syntax error in",25,25,300,50)
    $label=GUICtrlCreateLabel("20",25,85,50,40)
        GUICtrlSetColor(-1,0xF20000)
        GUICtrlSetFont(-1,30,1000)
    GUICtrlCreateLabel("seconds"&@CRLF&@CRLF& _
        "and result in an INDIVIDUAL error message.",25,150,300,50)
    GUICtrlCreateLabel("I hope you find it useful !"&@CRLF&@CRLF&"j.",25,220,300,80)
GUISetState()

For $i=19 To 0 Step -1
    Sleep(1000)
    GUICtrlSetData($label,$i)
Next

MsgBox(0,"" ; this is meant to produce an error !

Do
    $msg=GUIGetMsg()
Until $msg=-3

#region;-------------user script end






;############################################################################
;   2nd part (error func) copy and individualize to the end of your program
;############################################################################
#region;-------errorfunc
;   MadExcept option
Func _OnAutoItError($txt)
    Send("{ENTER}")
    GUICreate(@ScriptName,385,90)
    GUISetIcon("")
    GUISetBkColor(0xE0DFE2)
        GUICtrlSetBkColor(GUICtrlCreateLabel("",1,1,383,1),0x41689E)
        GUICtrlSetBkColor(GUICtrlCreateLabel("",1,88,383,1),0x41689E)
        GUICtrlSetBkColor(GUICtrlCreateLabel("",1,1,1,88),0x41689E)
        GUICtrlSetBkColor(GUICtrlCreateLabel("",383,1,1,88),0x41689E)
        GUICtrlCreateIcon("user32.dll",103,11,11,32,32)
        GUICtrlSetBkColor(GUICtrlCreateLabel("An error occurred in the application.",52,22,175,15),-2)
        GUICtrlSetBkColor(GUICtrlCreateLabel("",10,60,110,22),0x706E63)
            GUICtrlSetState(-1,128)
        $send=GUICtrlCreateLabel("   send bug report",28,64,92,15)
            GUICtrlSetBkColor(-1,-2)
            GUICtrlSetColor(-1,0xFFFFFF)
            GUICtrlSetCursor(-1,0)
        $sen=GUICtrlCreateIcon("shell32.dll",25,13,63,16,16)
            GUICtrlSetCursor(-1,0)
        GUICtrlSetBkColor(GUICtrlCreateLabel("",124,60,114,22),0xEFEEF2)
            GUICtrlSetState(-1,128)
        $show=GUICtrlCreateLabel("   show bug report",143,64,95,15)
            GUICtrlSetBkColor(-1,-2)
            GUICtrlSetCursor(-1,0)
        $sho=GUICtrlCreateIcon("shell32.dll",23,127,63,16,16)
            GUICtrlSetCursor(-1,0)
        GUICtrlSetBkColor(GUICtrlCreateLabel("",246,8,131,22),0xEFEEF2)
            GUICtrlSetState(-1,128)
        $cont=GUICtrlCreateLabel("   continue application",265,12,115,15)
            GUICtrlSetBkColor(-1,-2)
            GUICtrlSetCursor(-1,0)
        $con=GUICtrlCreateIcon("shell32.dll",290,249,11,16,16)
            GUICtrlSetCursor(-1,0)
        GUICtrlSetBkColor(GUICtrlCreateLabel("",246,34,131,22),0xEFEEF2)
            GUICtrlSetState(-1,128)
        $rest=GUICtrlCreateLabel("    restart application",265,38,115,15)
            GUICtrlSetBkColor(-1,-2)
            GUICtrlSetCursor(-1,0)
        $res=GUICtrlCreateIcon("shell32.dll",255,249,37,16,16)
            GUICtrlSetCursor(-1,0)
        GUICtrlSetBkColor(GUICtrlCreateLabel("",246,60,131,22),0xEFEEF2)
            GUICtrlSetState(-1,128)
        $close=GUICtrlCreateLabel("     close application",265,64,115,15)
            GUICtrlSetBkColor(-1,-2)
            GUICtrlSetCursor(-1,0)
        $clos=GUICtrlCreateIcon("shell32.dll",240,249,63,16,16)
            GUICtrlSetCursor(-1,0)
    GUISetState()
    WinSetOnTop(@ScriptName,"",1)
    Do
        $msg=GUIGetMsg()
        If $msg=$cont Or $msg=$con Then MsgBox(270400,"Continue Application", _
            "I am afraid, not possible with AutoIt !     ")
        If $msg=$show Or $msg=$sho Then MsgBox(270400,"Show Bug Report",$txt)
        If $msg=$send Or $msg=$sen Then
            ;#include <INet.au3>    ;   use email
            ;_INetSmtpMail ( $s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress [,$s_Subject&_
            ;[,$as_Body [,$s_helo, [,$s_first [,$b_trace]]]]])
            MsgBox(270400,"Send Bug Report","Email successfully sent !     ")
        EndIf
    Until $msg=-3 Or $msg=$close Or $msg=$clos Or $msg=$rest Or $msg=$res
    If $msg=$rest Or $msg=$res Then
        If @Compiled Then
            $x=Run(@ScriptName)
        Else
        ;   $x=Run("Autoit3.exe "&@ScriptFullPath)
            $x=Run('"Autoit3.exe" "'&@ScriptFullPath&'"')
        EndIf
    EndIf
    Exit
EndFunc
;   apologize option
Func _OnAutoItError1($txt)
    Send("{ENTER}")
    MsgBox(270336," :-(      So Sorry  ---  Individual Error Message","Script  <"& _
        @ScriptName&">  terminated."&@CRLF&@CRLF&"Error Message:"&@CRLF&@CRLF& _
        $txt&@CRLF&@CRLF&"The Author deeply apologizes for the inconvenience !"&@CRLF&@CRLF)
    ; or make a logfile or restart the script or whatever ......
    Exit
EndFunc
#endregion;-------errorfunc
;############################################################################
;   end 2nd part (error func)
;############################################################################

i will post this method in the example scripts section. look here.

j.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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