> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# arc:catch

> 在脚本中创建异常处理块，可选择性地或广泛地捕获 arc:try 或其它隐式 try 作用域中抛出的异常。

arc:catch 关键字用来在脚本中创建处理异常情况的代码块。除了 [arc:try](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/keyword-reference/op-arc-try.md)，还可以在以下任何的关键字中包含一个 arc:catch 块，其作用域用作隐式的 [arc:try](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/keyword-reference/op-arc-try.md) 部分：

* [arc:call](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/keyword-reference/op-arc-call.md)
* [arc:render](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/keyword-reference/op-arc-render.md)
* [arc:script](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/keyword-reference/op-arc-script.md)

## 参数

* **code**：code 参数可以允许选择性地捕获异常。要捕获所有异常，请使用字符 \*。

## 控制属性

* **\_code**：捕获异常的代码。
* **\_description**：捕获的异常的简单描述。
* **\_details**: 关于异常的更多信息（如果有）。

## 示例

在批处理文件或 shell 命令的错误输出时包装一条更加用户友好型的消息：

```xml theme={null}
<arc:try>
<arc:call op="sysExecute">
  <arc:check attr="sys:error">
    <arc:throw code="myerror" description="Batch file could not be executed" details="[sys:error]"/>
  </arc:check>
</arc:call>
<arc:catch code="*">
  <arc:call op="appSendEmail"/>
</arc:catch>
</arc:try>
```

抛出并捕获异常。在 [arc:call](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/keyword-reference/op-arc-call.md) 中，RSBException 被抛出并捕获。在关键字的作用域中，`arc:ecode` 和 `arc:emessage`属性被添加到当前的对象中并推出。

```xml theme={null}
<arc:call op="...">
  <arc:throw code="myerror" description="thedescription" details="Other Details."/>
  <arc:catch code="myerror">
    <arc:set attr="arc:ecode" value="[_code]"/>
    <arc:set attr="arc:emessage" value="[_description]: [_details]"/>
    <arc:push/>
  </arc:catch>
</arc:call>
```

捕获所有异常：

```xml theme={null}
<arc:catch code="*">
  An exception occurred. Code: [_code], Message: [_description]
</arc:catch>
```

## 另请参阅

* [arc:try](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/keyword-reference/op-arc-try.md)：定义一个用于捕获异常的作用域。
* [arc:throw](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/keyword-reference/op-arc-throw.md)：强制执行异常。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.