Home > Running a Script > Handling Errors & Logging > Error Handling Overview

Error Handling Overview

During the Script execution, an error may occur. For example a function fails because the application to launch is specified with an invalid path, or a click on a link within a web page cannot be done because the link does not exist anymore.

This article explains how WinTask handles errors by default and explains how you can handle errors in a custom way.

Default Error Handling Mechanism

If an error occurs during the Script execution, an error message is displayed and Script Execution stops. The error message returns the name of the script where the error occurred (file extension is .ROB as it is the executable script, not the source file), the line number for the error and some text explaining the error.

The error message is displayed after a default timeout of 30 seconds. You can change this default value by setting a different value for the system variable #ActionTimeout.

So if a web page loads in more that 30 seconds, the UsePage execution for this page will report an error. Or if the script waits for a window telling when a file download has finished but the file download takes more than 30 seconds, the UseWindow detecting the end of the download will report an error. Change momentarily the value of #ActionTimeout for avoiding a too early execution error.

Ignore the error and resume execution on the next line of Script

If an error occurs, the Script execution continues as if no error occured. However, the error may have side effects, such as user action not replayed, condition not met, and so on. It is the responsibility of your code to test for an error condition and take appropriate action. You do this by testing the value of the return code of the function which can return an error.

The system variable #IgnoreErrors is used to switch from the default error handling to the ignore error mechanism:

#IgnoreErrors=1

means that for all the subsequent lines, any error is ignored.

By switching to:

#IgnoreErrors=0

for all the subsequent lines following this line, the default error handling mechanism is used (so as soon as an error occurs, an error is displayed and script execution stops).


NOTE: do not set #IgnoreErrors to 1 when you debug a script as no error message is then displayed!



Execute a piece of code when an error occurs (OnAction Error) - for advanced programmers

If OnAction Error structure is used, when an error occurs, the error procedure as defined in OnAction Error is executed. Such an error procedure can take a screenshot of the desktop or of the application window, send a mail, log the error, chain with another script, etc...See OnAction Error article.
 

Stop execution after a timeout and execute another script - for advanced programmers

When  is used for measuring response times or availability, scripts are run very frequently and need to run whatever happened during the previous execution. 


Two system variables can be used to make a script execute repeatedly whatever happened during the previous execution. End

See #ExecTimeout article.

See #ScriptAfterTimeout$ article.

The following articles explain how you can resolve typical issues that occur during a script execution.

Handling Unexpected Windows
Handling Object not found Error
Handling Page Timeout Error
Handling Inacurrate ClickHTMLElement
Handling Incorrect Typing
Handling Pause Error
Logging Execution