Sign in to follow this  
Followers 0
TheFluffyOne

Hiding errors at runtime

13 posts in this topic

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?

Share this post


Link to post
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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

@Jos

Thanks for correcting me :)

It would be better to make option for ignore options and if fatal error occurs then redirect to function for exit like user want...

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Many thanks to everyone for the replies, and sorry for not acknowledging them sooner -- I really must turn on watching of my own posts :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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

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