Sign in to follow this  
Followers 0
zackrspv

Handle Global Script Errors

3 posts in this topic

Hi!

Since i've been having fun writing some rather function heavy scripts, I was wondering how it would be possible to catch global errors in the script. For example, sometimes, when the script runs, it may error out saying '-1, the requested action with this object has failed'; as I do not know where it is erroring out, especially when one of my users is using the program, it would be nice to have some sort of error check/handle for the entire script instead of having to constantly check @error = 0 or 1 lol

Secondly, is there a way to give more DETAIL on what the error was so that the program doesn't close, or that I can write an error handle routine that catches all global errors in the script to help the client out more?

Thanks!


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites



Since you mentioned object I assume that you use some kind of COM, in that case you can register you rown COM error function like this (Copied from the helpfile):

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler 

; Performing a deliberate failure here (object does not exist)
$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.bogus 
if @error then Msgbox(0,"","the previous line got an error.")

Exit 


; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1) ; something to check for when this function returns 
Endfunc

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Since you mentioned object I assume that you use some kind of COM, in that case you can register you rown COM error function like this (Copied from the helpfile):

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler 

; Performing a deliberate failure here (object does not exist)
$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.bogus 
if @error then Msgbox(0,"","the previous line got an error.")

Exit 


; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1) ; something to check for when this function returns 
EndfuncoÝ÷ Ûú®¢×ëZºÚ"µÍKIÍÈQK]LÈËLHØ[ÈÛH[Ý[Û[[[Ý[Û×ÒQRÓØKØ[ÝYÚÝ[[Ü[Ø[ÝÓÓHÜÈ
ÙHÒQQÜ[YÚÝ
HÈYÚÝHÙÜ[

If i remove the code above i get no error. When i register my IEErrorHandlerRegister, i get no issues. But i don't want to just trap _IE errors; i want to be able to trap any error that auto.it throws out to a user; esp those where it wouldn't work properly on their system (admin rights, etc). Hence, I need to figure out a global error handler.


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

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