> ## 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 範圍中擲回的例外。

export const siteNameShort = "知行之橋";

arc:catch 關鍵字用來在指令碼中建立處理例外情況的程式碼塊。除了 [arc:try](./op-arc-try)，還可以在以下任何的關鍵字中包含一個 arc:catch 塊，其範圍用作隱式的 [arc:try](./op-arc-try) 部分：

* [arc:call](./op-arc-call)
* [arc:render](./op-arc-render)
* [arc:script](./op-arc-script)

## 參數

* **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](./op-arc-call) 中，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](./op-arc-try)：定義一個用於捕獲例外的範圍。
* [arc:throw](./op-arc-throw)：強制執行例外。
