Jump to content
Sign in to follow this  
kiffab

Advice re Error Handling

Recommended Posts

kiffab

Hi Guys

I am building a monitoring tool which is almost complete.

This is in the form of a dashboard reading data from various log files, databases, etc. As you can imagine with various data sources, there is a possibility that the application can error (missing files, files refreshing, SQL down, etc).

Most of the AutoIt errors I have seen exit upon failure. What's the best way to handle this in my app? I plan to write to a database by calling a function before it closes. For example :

DBConnect('Error', 'Server X', $time, 'unable to connect to sql database')

What is the cleanest way to "error" but continue running? Use the "break" command?

Thanks, appreciate any input.

K.

Share this post


Link to post
Share on other sites
jdelaney

You need to validate things prior to performing actions...such as IsObj() for db...that way, you don't perform methods, or get properties, from things you expect to be an object, but are not...same is true for files, through FileOpen, with your proper mode, and verifying not @error


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
water

I would split your script into several functions.

The main function displays the dashboard. For every data type I would create a separate function (read a file, read a SQL database etc.) to retrieve the data. Each of this functions returns the data (on success) or sets @error. If @error is set the main function then can display the error message or a "Not available" for the the corresponding data.

Each retrieve function has to handle all possible errors and set @error accordingly.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
kiffab

Hi Water

That is how it works. I have a GUI that just calls the function. Each function exists in it's own file and updates the GUI in some way.

An example may help:

Func SQLCheck()

$time = @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC

TCPStartup()
$server = TCPNameToIP("MyDatabaseServer")
$port = 1433

$socket = TCPConnect($server,$port)
Switch $socket
    Case -1
            $SQLCheck = 1
                If $SQLCheck <> $SQLCheck_old Then
                    GUICtrlSetData($06_schematic_sql , _SetImage($06_schematic_sql, @ScriptDir & "buttonsschematic_down.png"))
                    DBConnect('SQL', 'SQL DB', $time, 'Down')
                    $SQLCheck_Old = $SQLCheck
                EndIf

    Case Else
            $SQLCheck = 2
                If $SQLCheck <> $SQLCheck_old Then

                    GUICtrlSetData($06_schematic_sql , _SetImage($06_schematic_sql, @ScriptDir & "buttonsschematic_up.png"))
                    $SQLCheck_Old = $SQLCheck
                EndIf
EndSwitch

TCPShutdown()

EndFunc

SQLcheck flags are set to 0 when the main GUI is reset or opened for the first time. I use these to try and update the image only when required (i.e. status change)

Share this post


Link to post
Share on other sites
water

Looks good.

You just have to make sure that you grab all possible errors.

So after TCPStartup and TCPNameToIP I would insert a check to make sure that @error = 0. If not, display the error sign.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×