Catch Error
Command description
Some commands validate their execution status and may raise errors. An unhandled error stops the automation. Use Catch Error to handle errors raised by any nested child command, workflow, or imported command. After the error is caught, execution continues with the next sibling command after Catch Error. This is equivalent to Python's try/except syntax.
Command Input Parameters
None
Command Output Parameters
None
Example 1
If the target element does not exist, Click Desktop Element raises an error and line 3 is skipped. Catch Error handles the error, and execution continues with its next sibling command on line 4.
Corresponding Python code
# -*- coding: utf-8 -*-
import sys
from builtin import *
from debuger import call_flow_wrapper
def run(args):
try:
click_win_element(ElementDescriptor('d74d3a47-420b-4d27-99f1-5ccdb4aedf79', "Login"))
print_to_app("If the element is clicked successfully, the log will be output, otherwise it will not be output", {"renderHtml":True})
set_flow_exception(None)
except Exception as e:
set_flow_exception(e)
if has_exception():
err = get_flow_exception()
print_to_app("Error when clicking element", {"renderHtml":True})
print_to_app(err, {"renderHtml":True})
print_to_app("Application ended normally", {"renderHtml":True})
@call_flow_wrapper("main process")
def main(args=None):
return run(args)
Example 2
[
{
"children": [
{
"children": [],
"in": {
"Log Content": "\"Exceptions thrown will be intercepted\"",
"Render HTML": "False",
"Log Type": "'INFO'"
},
"out": {},
"comments": "",
"ins": "Print Log"
}
],
"in": {},
"out": {},
"comments": "",
"ins": "Catch Error"
},
{
"children": [
{
"children": [],
"in": {},
"out": {
"Error": "err"
},
"comments": "",
"ins": "Get Caught Error"
},
{
"children": [],
"in": {
"Log Content": "err",
"Render HTML": "False",
"Log Type": "'INFO'"
},
"out": {},
"comments": "",
"ins": "Print Log"
}
],
"in": {},
"out": {},
"comments": "",
"ins": "If Error Is Caught"
},
{
"children": [
{
"children": [],
"in": {
"Log Content": "\"No error\"",
"Render HTML": "False",
"Log Type": "'INFO'"
},
"out": {},
"comments": "",
"ins": "Print Log"
}
],
"in": {},
"out": {},
"comments": "",
"ins": "If No Error Is Caught"
},
{
"children": [],
"in": {
"Log Content": "\"Continue execution\"",
"Render HTML": "False",
"Log Type": "'INFO'"
},
"out": {},
"comments": "",
"ins": "Print Log"
}
]