Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

Try、Catch、および Throw コマンド

Try/Catch 文では、コード・ブロック (Try 内) の実行時エラーの発生を監視し、発生した場合、例外を生成して実行を別のコード・ブロック (Catch 内) に移し、そこでエラーを処理できます。Throw コマンドでは、明示的に例外を生成できます。通常 Throw は、Catch の上位レベルに実行を移すことを目的として、Catch ブロック内で使用されます。Catch 内の $Zerror システム変数には、エラー情報が格納されます。

Note:

CatchThrow のどちらも exception 引数を取ります。これは例外情報を格納するオブジェクトです。Caché でのオブジェクトの操作については、後で簡単に説明しますが、Caché 例外オブジェクトの詳細はこのチュートリアルの対象範囲ではありません。

SAMPLES>try {write "hello", 1/0} catch {write !,"A ", $zerror, " error occurred"}
hello
A <DIVIDE> error occurred
SAMPLES>
FeedbackOpens in a new tab