Jump to content

Hiding errors at runtime


Recommended Posts

I've got a bunch of scripts that get run on end-user machines, and if a condition occurs that I didn't think to handle (ahem) the user gets a dialog on their screen telling them there was an AutoIt error -- not desirable!

Having had a dig around, I've found the OnExitFunc option, which sounded like it might allow me to hide the error message, however it either doesn't work that way or I'm not using it correctly:

Opt("OnExitFunc", "myExitFunction")
callInvalidFunction()

Func myExitFunction()
    ConsoleWriteError("An error occurred: " & @error)
EndFunc

I appreciate that the ConsoleWriteError is pretty useless here; it's just a placeholder for some more sensible code to output debug information to a file. The problem is that when I compile this to an EXE it doesn't seem to make a difference. I still get a dialog on the screen advising me of the error.

Do I have the right function, or is there another way to do this?

Link to comment
Share on other sites

@TheFluffyOne

OnAutoitExit function is only called when autoit exit, its not for prevent from autoit errors...

Before, there were Opt('RunErrorsFatal', 0) but now you cant disable fatal error messages (I think), so you will have to make script without errors :)

Cheers, FireFox.

Link to comment
Share on other sites

  • Developers

Before, there were Opt('RunErrorsFatal', 0) but now you cant disable fatal error messages (I think), so you will have to make script without errors :)

Not a valid statement!

This options was only to catch Run() errors .. nothing more ..nothing less .. which is obsolete with the new implementation.

There is no autoit3 option to suppress the error other then proper coding or shelling the compiled script with parameter /ErrorStdOut which will redirect the error information to STDOUT.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I've got a bunch of scripts that get run on end-user machines, and if a condition occurs that I didn't think to handle (ahem) the user gets a dialog on their screen telling them there was an AutoIt error -- not desirable!

Having had a dig around, I've found the OnExitFunc option, which sounded like it might allow me to hide the error message, however it either doesn't work that way or I'm not using it correctly:

Opt("OnExitFunc", "myExitFunction")
callInvalidFunction()

Func myExitFunction()
    ConsoleWriteError("An error occurred: " & @error)
EndFunc

I appreciate that the ConsoleWriteError is pretty useless here; it's just a placeholder for some more sensible code to output debug information to a file. The problem is that when I compile this to an EXE it doesn't seem to make a difference. I still get a dialog on the screen advising me of the error.

Do I have the right function, or is there another way to do this?

You should try a function ObjEvent("Autoit.error", myerrorfunction). This catch the exception an handle it with myerrorfunciont.

http://www.autoitscript.com/autoit3/docs/f...ns/ObjEvent.htm

Saludos.

Link to comment
Share on other sites

  • Developers

You should try a function ObjEvent("Autoit.error", myerrorfunction). This catch the exception an handle it with myerrorfunciont.

http://www.autoitscript.com/autoit3/docs/f...ns/ObjEvent.htm

Saludos.

Did it work for you?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Yeah... this function is only COM error event handler. It will not catch this within the handler function but if compiled it'll produce the unwanted MsgBox you want to avoid but it's much better than watching your stack flowed...:

Dim $rrr = Recursive(0)
MsgBox(0x40, 'Title', $rrr)


Func Recursive($i)
    If $i = 5000 Then Return $i
    Return $i+Recursive($i+1)
EndFunc
Link to comment
Share on other sites

Write better code.

;;; DONT!!!!!!!!!!!!!!
$IpInput = InputBox("", "Enter your IP address")
$aSplit = StringSplit($IpInput,".")
MsgBox(0,"","Your ip is: " & $aSplit[1] & "." & $aSplit[2] & "." & $aSplit[3] & "." & $aSplit[4])


; DO!!!!!!!!!
$IpInput = InputBox("", "Enter your IP address")
If @error Then Exit
$aSplit = StringSplit($IpInput,".")
If Not @error And $aSplit[0] == 4 Then
    MsgBox(0,"","Your ip is: " & $aSplit[1] & "." & $aSplit[2] & "." & $aSplit[3] & "." & $aSplit[4])
EndIf
Link to comment
Share on other sites

Write better code.

Dude seriously? :) Jesus if ya ain't gonna try to help someone out then don't even reply man

Yea FluffyOne, try what tanno suggested: ObjEvent("AutoIt.Error", "myerrorfunction") I was getting a Line -1: error and it fixed the problem for me.

Edited by b1naryatr0phy
Link to comment
Share on other sites

Dude seriously? :) Jesus if ya ain't gonna try to help someone out then don't even reply man

Yea FluffyOne, try what tanno suggested: ObjEvent("AutoIt.Error", "myerrorfunction") I was getting a Line -1: error and it fixed the problem for me.

Dude, what the hell?? Manadar is right, you don't swipe your errors under rug and hope they disappear, you write better code so there isn't any errors. Edited by AdmiralAlkex
Link to comment
Share on other sites

Dude, what the hell?? Manadar is right, you don't swipe your errors under rug and hope they disappear, you write better code so there isn't any errors.

I agree completely, but people go to forums for help, not to get mocked. What the hell is wrong with this forum anyway good lord. Maybe some of yall need to get off the pedestal your on and stop acting like your better than anyone who is still learning.

Dont get me wrong, there are some extremely helpful people here, but i emphasize some

Edited by b1naryatr0phy
Link to comment
Share on other sites

Sorry, b1naryatr0phy. Sometimes it is hard to determine the cause of the error, often because of misinformation, information lacking or a language barrier and it is hard to give a reply that makes sense at all times.

For your information, I am trying to help out. I have shown how to capture errors in AutoIt using @error and shown a case in which it is very useful.

Edited by Manadar
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...