UiPath Documentation
studio-web
latest
false
Studio Web 用户指南
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。

Try Catch 异常处理

将“Try Catch 异常处理”活动添加到 Studio Web 中的 API 工作流中,以便使用回退操作处理由 API 故障、无效数据或意外错误导致的异常。

“Try Catch异常处理”活动在工作流中提供结构化异常处理。使用它来定义 API 故障、数据无效或意外错误的回退操作。

使用“Try Catch 异常处理”活动​

要将“Try Catch 异常处理”活动添加到工作流中,请执行以下操作:

  1. 在 API 工作流设计器画布上,选择加号 (+) 图标。系统将显示“添加活动”菜单。

  2. 选择“更多…” ,然后选择“Try Catch 异常处理”。

  3. 在“属性”面板中,为错误命名。

  4. Optionally, configure retries for the Try block:

    • Retry—Turn on to automatically retry the Try block when it fails. Off by default.
    • Max retries—The maximum number of retry attempts.
    • Initial delay—The delay before the first retry attempt.
    • Backoff—The strategy used to increase the delay between subsequent retry attempts.

    The Preview of retry schedule panel shows the computed delay for each retry attempt based on these settings.

  5. 前往“尝试”块添加活动。这是为错误而监控的活动。

  6. 在Catch块中定义错误处理逻辑。如果Try块中的任何步骤失败,则执行将转换到Catch流程。

  7. 调试工作流以执行活动并生成输出字段以供以后使用。

When retries are enabled, each retry attempt appears as a separate entry in the run output, so you can review the result of every attempt.

访问错误详情​

当Try块中发生错误时, “Try-Catch 异常处理”活动会公开结构化的错误详细信息。要访问错误详细信息,请使用$context.outputs.Try_Catch_X.error或$error 。

错误对象保持一致的结构,如下所示:

"Try_Catch_1": {
        "error": {
          "type": "<runtime error source>",
          "title": "<summary error message>",
          "status": <response status code>,
          "detail": "<detailed error message",
          "data": {},
        }
      }
"Try_Catch_1": {
        "error": {
          "type": "<runtime error source>",
          "title": "<summary error message>",
          "status": <response status code>,
          "detail": "<detailed error message",
          "data": {},
        }
      }

错误详细信息包括:

  • 类型— 指示错误的 Runtime 来源。
  • title — 提供简明的错误摘要。
  • “状态” — HTTP 状态代码(如果适用)。
  • detail — 提供错误的详细说明。
  • data — 包括有关失败任务的其他元数据。此字段可能并不总是处于填充状态。

您可以引用这些属性来构建结构化错误响应或触发警示。

  • 使用“Try Catch 异常处理”活动​
  • 访问错误详情​

此页面有帮助吗?

连接

需要帮助? 支持(opens in new window)

想要了解详细内容? UiPath Academy(opens in new window)

有问题? UiPath 论坛(opens in new window)

保持更新