Jump to content

Extend Error Fucntions


Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...