Jump to content
Sign in to follow this  

Help with Error Handling

Recommended Posts


Hi everyone,

I'm fairly new with AutoIT but not to programming, I've managed to create some good scripts for my job however I've always struggled with Error Control / Handling. I've mainly made TCP event driven apps which have over 200 client connections and at times I get errors and the client just stops - ideally I'd like to handle these errors and be able to recover or in a worst case scenario, re-start the application.

My issue is that whatever I try to "catch" errors, it never seems to work ;)

Here's a very simple test of error handling which, I believe should work - but doesn't:

; Error Control Test
; Wanting to handle basic errors

Global $EControl  = ObjEvent("AutoIt.Error", "ErrorControl")
Dim $VarA
Dim $VarD[1]

; Create undefined variable error
$VarA = $VarB & $VarC

; Create undimensioned variable error
$VarD[5] = "Testing"

Func ErrorControl()
    ; Intercept Error Message
    ConsoleWriteError("Error Caught: " & $EControl.description & " (" & $EControl.number & ")" & @CRLF)
    return 0

Neither "errors" are caught and just end up quitting the application.

Any ideas what I'm doing wrong?


Share this post

Link to post
Share on other sites

Catching COM errors can't help you when something outside COM breaks down, so forget what you just wrote.

You should have a "parent" script that Run() the real one with the /ErrorStdOut, and then catch error that way.

I think it's read by StdoutRead but don't know, I haven't actually done this myself.

Share this post

Link to post
Share on other sites

Thank you - I hadn't thought about doing it that way!

As the arrays in my scripts can be redimensioned by events, even with a locking variable I've not been able to get around these kinds of errors. But this is the perfect solution ;)

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