Sign in to follow this  
Followers 0
littleclown

Auto IT error

18 posts in this topic

Sorry, if the answer on my question is somewhere in the forum, but I can't find anything.

I need to log the AutoIT errors - full information - the error line and explanation. I need to write this into logfile.

10x

Share this post


Link to post
Share on other sites



In SCITE click tools then click Trace: Add Trace Lines. That will write everything to the SCITE console. There are also other options on there you can mess with.


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

10x, but I want to log a compiled .exe file in log file.

Share this post


Link to post
Share on other sites

Then you are going to have to go through your script and add this:

#include <File.au3>
_FileWriteLog ( $sLogPath, $sLogMsg )

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

My problem is not the log file. I already have a logging function, but how can I catch the error msg and put it to the file (I am newbie :P )

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You would use the @Error macro. Just place the @error after a function. The error code will be stored in the @error macro. So for example:

#include <file.au3>
$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error Then
        _FileWriteLog ("log.log","Error on line " & @ScriptLineNumber & ".  The error code after the fileread() function was " & @error & ".")
        ExitLoop
   Endif
Wend
FileClose($file)
Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Yes. For some errors I can use this, and I will. 10x.

But how can I get errors like

"If" statement has no matching "EndIf" statement.:

This sort of errors - the critial ones :P.

I have about 500 lines of code for know and I don't know what will be happen in all situations - where are my errors, etc.

I need to put this error in a file.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

For an If statement, you give it a list of possibilities. In the event that none of the possibilities match, you use en Else statement.

If $green = "green" Then

Elseif $blue = "blue" Then

Elseif $red = "red" Then

Elseif $yellow = "yellow" Then

Else
    MsgBox(16,"Error!","None of your if statements matched!!!")
    ;Write the error to log file here
    ;Exit the application here
Endif
Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

But what about syntax errors?

Share this post


Link to post
Share on other sites

Use the Syntax check that comes with SCITE. Plus, autoit in many cases won't even run if there are syntax errors. Upon being executed it will just error right off the bat and give an error messagebox telling that there was an error on line whatever.


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Yes but I have many If, until, do, for, select, etc. SCITE don't check all possible situations, and I didn't test all, cuz I can't simulate everything. I afraid about syntax errors in critical moments, when some stupid guy is on the PC.

Share this post


Link to post
Share on other sites

:P huh?

If you compiled the script into a exe, and you tested it, then whats the problem? What you are saying makes no sence. The only way what you are saying is to happen is to have the script be decompiled. Do a ctrl+alt+F5 to test your code. Run Tidy. If it works, then your fine. If a user reports a bug, get them to screenshot the error screen when it happens, and save it to a word doc. You are making this WAY too hard on yourself.

Share this post


Link to post
Share on other sites

Yes, but why I have not a function to catch some bugs? :P The Word document with shot is not so automated fot autoIT :D.

Anyway, ctrl+alt+F5 working fine for me :).

10x all

Share this post


Link to post
Share on other sites

What you are talking about would involve having a second script run to catch the errors. It would have the errors be reported say to the event viewer, or to a log file. It would look for the error window that AutoIt makes, and do a text read to capture the data. Once you capture the data, you would have to decide what to do with it.

Share this post


Link to post
Share on other sites

This example from help file is useful:

; COM Error Handler example
; ------------------------- 

$oIE=ObjCreate("InternetExplorer.Application.1"); Create Internet Explorer application
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Initialize a COM error handler



$oIE.UnknownMethod  ; Deliberately call an undefined method

If @error then
  Msgbox (0,"AutoItCOM test","Test passed: We got an error number: " & @error)
Else
  Msgbox (0,"AutoItCOM test","Test failed!")
Endif

Exit

; This is my custom defined error handler
Func MyErrFunc()

  $HexNumber=hex($oMyError.number,8); for displaying purposes
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF _
            )
  SetError(1) ; to check for after this function returns
Endfunc

10x :P.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

This example from help file is useful:

; COM Error Handler example
; ------------------------- 

$oIE=ObjCreate("InternetExplorer.Application.1"); Create Internet Explorer application
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Initialize a COM error handler
$oIE.UnknownMethod; Deliberately call an undefined method

If @error then
  Msgbox (0,"AutoItCOM test","Test passed: We got an error number: " & @error)
Else
  Msgbox (0,"AutoItCOM test","Test failed!")
Endif

Exit

; This is my custom defined error handler
Func MyErrFunc()

  $HexNumber=hex($oMyError.number,8); for displaying purposes
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF _
            )
  SetError(1); to check for after this function returns
Endfunc

10x :P.

That only works for COM object errors. This:

ObjEvent("AutoIt.Error","MyErrFunc"); Initialize a COM error handler

is a COM error handler as stated by the comment following it. It will therefore only work with COM objects. This type of error handling won't work if you just want it to go to a function when there is an error in standard autoit code. You have to manually write error handling functions into your code in every place where an error may occur. That is really the only way to do it correctly. The easiest way to do this is to simply write error handling into your script as you write it. That way it isn't a pain in the ass when you finish the script, because if you didn't do it while you were writing it, you now have to go back into the script and add the error handling in.

Sorry, but that is really the only way to do it. I know, because i have had to go back into my scripts and write error handling for them and it is quite painful. :D

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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