Sign in to follow this  
Followers 0
lynwode

Extend Error Fucntions

6 posts in this topic

Howdy Folks,

I'm new to the world of AutoIt so apologise if my question is a "newbie" mistake.

I have inherited a script that needs some additional functionality, namely the logging of all errors to a MySQL table. The previous developer appears to be logging errors using the SetError function - which looks to be a pre-defined builtin. Is there anyway of extending this easily or is the best method to write my own custom error handling routine and then refactor all 20k lines of the script?

Any thoughts would be greatly appreciated.

Cheers,

Tim.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

20k lines?... Does it run your whole company???

SetError is a standard function, it's what you use to set a specific error and extended information within a function before that function is returned from.  However, the error data returned is not standard.  It's predefined only by the coder (unless it's a UDF or a Standard function).

You could obviously create your own standardized error/extended return values, go through each function, and replace with those.

Because of the broadness of the issue, I can't think of anything that would suffice more than that off the top of my head at the moment.

Edit:

I guess 20k isn't that many lines of code if you're counting all the includes they didn't write.  But if your code management is 20k lines... oh boy.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Welcome to AutoIt and the forum!

Could you please post an example how SetError is now used for error handling?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks SmOke_N,

I think have confirmed my worst fears that a custom function is the way forward.

Share this post


Link to post
Share on other sites

Hi Water,

If condition Then
TraceMsg("Successfully executed the query ")
Else
ErrorMsg("Failed to execute the query ")
Return SetError(0,0,False)
EndIf

What I need  to do in this example is write the error to an MySQL DB.

 

Share this post


Link to post
Share on other sites

I would do the following:

  • Create ONE function to handle all kind of messages (information, warning, error messages). Means: Combine functions TraceMsg and ErrorMsg into a single function
  • Pass the severity of the message to the new function. Example (1 = information (e.g. "Successfully executed"), 2 = Warning (e.g. "Record already exists"), 3 = Error (e.g. "Record could not be created"), 4 = Abort (e.g. Could not connect to database, Script exited"))
  • Create a new function to query / set the target of the messages (Console, flat file, MySQL DB etc.) plus the minimum message severity to be logged.

If needed I could provide an example.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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  
Followers 0