> ## 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-Hant/scripting/keyword-reference/op-arc-try.md)，還可以在以下任何的關鍵字中包含一個 arc:catch 塊，其範圍用作隱式的 [arc:try](https://docs.kasoftware.com/26.4/self-hosted/zh-Hant/scripting/keyword-reference/op-arc-try.md) 部分：

* [arc:call](https://docs.kasoftware.com/26.4/self-hosted/zh-Hant/scripting/keyword-reference/op-arc-call.md)
* [arc:render](https://docs.kasoftware.com/26.4/self-hosted/zh-Hant/scripting/keyword-reference/op-arc-render.md)
* [arc:script](https://docs.kasoftware.com/26.4/self-hosted/zh-Hant/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-Hant/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-Hant/scripting/keyword-reference/op-arc-try.md)：定義一個用於捕獲例外的範圍。
* [arc:throw](https://docs.kasoftware.com/26.4/self-hosted/zh-Hant/scripting/keyword-reference/op-arc-throw.md)：強制執行例外。


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