catch
(expression)
catch は、取り消し可能、照会不可能、および編集不可能です。
このキーワードは MEL エクスプレッションを引数として使用します。カッコ内のエクスプレッションがランタイム エラーを生成した場合に 1 を、しなかった場合に 0 を返します。 このエクスプレッションは、ユーザが実行時のエラーをチェックして解決できるように設計されています。catch を使用すると、スクリプトの実行パスを介してランタイム エラーが伝播バック アップされるのを止めることができます。通常、ランタイム エラーが発生すると、スクリプトまたはプロシ-ジャの実行は終了します。catch コマンドは、警告ではなくエラーのみを認識します。 catch ステートメントのカッコ内の MEL コードは、MEL コマンドまたはプロシージャへのコールのように単一のエクスプレッションを指定してください。下記の例を参照してください。 注: catch はコマンドではありません。MEL 言語のキーワードです。MEL スクリプトで使用すると、コマンドの呼び出しというよりも、プロシージャ コールに近くなります。| int | 0 または 1 |
// Call to MEL command
//
if ( catch( `createNode -name myTransform transform` ) ) {
print "Could not create sphere\n";
} else {
// continue on as usual...
}
// Use of MEL C style procedure call syntax
//
if ( catch( advanceToNextDrivenKey( "","" ) ) ) {
print "Could not advance\n";
} else {
// continue on as usual...
}
// Set $divisor to 0 just to trigger an exception
//
int $divsor = 0;
int $factor;
if ( catch ($factor == 42/$divsor) ) {
print "Attempt to divide by zero caught\n";
} else {
// continue on as usual...
}
// This example shows how catch can be used to handle failure of commands
// or procedures. This will catch errors and calls to procedures that do
// not exist.
catch ( `underConstruction` );
// Without the catch, if the execution of underConstruction failed at
// runtime, the whole script containing the call would fail. Using catch
// enables this script to continue execution even if something fails.