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

# arc:catch

> スクリプト内に例外処理ブロックを作成し、arc:try または他の暗黙的なtry スコープ内でスローされた例外を選択的または広範囲にキャッチできるようにします。

export const siteNameShort = "Arc";

`arc:catch` キーワードを使用して、スクリプト内で例外処理ブロックを作成します。[arc:try](./op-arc-try) に加え、次のキーワード内で`arc:catch` ブロックを有することができます。スコープは黙示的`arc:try` セクションとして機能します：

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

## パラメータ

* **code**：選択的に例外をキャッチすることを許容します。すべての例外をキャッチするには、アスタリスク（`*`）を使います。

## アトリビュートの制御

* **\_code**：キャッチされた例外のコード。
* **\_description**：キャッチされた例外の短い説明。
* **\_details**：例外のより詳細な説明。

## 例

バッチファイルやシェルコマンドからのエラー出力に、よりユーザーフレンドリーなメッセージをラップします：

```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="*">
  例外が発生しました。Code: [_code], Message: [_description]
</arc:catch>
```

## 関連項目

* [arc:try](./op-arc-try)：例外をキャッチするスコープを定義する。
* [arc:throw](./op-arc-throw)：例外を強制する。
