CodeTryCatchFinallyStatement
メンバ
コンストラクタ
- public CodeTryCatchFinallyStatement();
-
- 概要
- System.CodeDom.CodeTryCatchFinallyStatement クラスの新しいインスタンスを初期化します。
- 例
-
// オブジェクト CodeTryCatchFinallyStatement ctcfs = new CodeTryCatchFinallyStatement(); // try // { // }
- public CodeTryCatchFinallyStatement( CodeStatement[] tryStatements, CodeCatchClause[] catchClauses );
-
- 概要
- 新しいインスタンスを初期化、 System.CodeDom.CodeTryCatchFinallyStatement クラス一度実行するために指定されたステートメントを使用して、catch句。
- パラメーター
-
- tryStatements
- 配列 System.CodeDom.CodeStatement を試すには、ステートメントを示すオブジェクト。
- catchClauses
- 配列 System.CodeDom.CodeCatchClause catch 句を示すオブジェクト。
- public CodeTryCatchFinallyStatement( CodeStatement[] tryStatements, CodeCatchClause[] catchClauses, CodeStatement[] finallyStatements );
-
- 概要
- 新しいインスタンスを初期化、 System.CodeDom.CodeTryCatchFinallyStatement クラスの指定されたステートメントを使用して、一度実行するため、句、および最後にステートメントをキャッチします。
- パラメーター
-
- tryStatements
- 配列 System.CodeDom.CodeStatement を試すには、ステートメントを示すオブジェクト。
- catchClauses
- 配列 System.CodeDom.CodeCatchClause catch 句を示すオブジェクト。
- finallyStatements
- 配列 System.CodeDom.CodeStatement オブジェクトを示す、最後を使用してステートメントです。
プロパティ
- public CodeStatementCollection TryStatements{ get; }
-
- 概要
- トライするステートメントを取得します。
- 戻り値
- A System.CodeDom.CodeStatementCollection を示すステートメントを実行してください。
- public CodeCatchClauseCollection CatchClauses{ get; }
-
- 概要
- 使用する catch 句を取得します。
- 戻り値
- A System.CodeDom.CodeCatchClauseCollection を示す catch 句を使用します。
- public CodeStatementCollection FinallyStatements{ get; }
-
- 概要
- 使用する finally ステートメントを取得します。
- 戻り値
- A System.CodeDom.CodeStatementCollection を示す、finally ステートメントです。
- EndDirectives
- 終了ディレクティブを含む CodeDirectiveCollection オブジェクトを取得します。 (Inherited from CodeStatement)
- LinePragma
- コード ステートメントのある行を取得または設定します。 (Inherited from CodeStatement)
- StartDirectives
- 開始ディレクティブを含む CodeDirectiveCollection オブジェクトを取得します。 (Inherited from CodeStatement)
- UserData
- 現在のオブジェクトのユーザー定義可能なデータを取得します。 (Inherited from CodeObject)
- Equals(Object)
- 指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。 (Inherited from Object)
- GetHashCode()
- 既定のハッシュ関数として機能します。 (Inherited from Object)
- GetType()
- 現在のインスタンスの Type を取得します。 (Inherited from Object)
- MemberwiseClone()
- 現在の Object の簡易コピーを作成します。 (Inherited from Object)
- ToString()
- 現在のオブジェクトを表す文字列を返します。 (Inherited from Object)
例
次のコード例を使用、CodeTryCatchFinallyStatementを定義、try... catch… finally の例外処理ステートメント。
// Declares a type to contain a try...catch block.
// 試み...catchブロックを含むように、タイプを宣言する。
CodeTypeDeclaration type1 =
new CodeTypeDeclaration(
"TryCatchTest"
);
// Defines a method that throws an exception of type System.ApplicationException.
// タイプSystem.ApplicationExceptionの例外を投げる方法を定義する。
CodeMemberMethod method1 = new CodeMemberMethod();
method1.Name = "ThrowApplicationException";
method1.Statements.Add(
new CodeThrowExceptionStatement(
new CodeObjectCreateExpression(
"System.ApplicationException",
new CodePrimitiveExpression(
"Test Application Exception"
)
)
)
);
type1.Members.Add( method1 );
// Defines a constructor that calls the ThrowApplicationException method from a try block.
// 試みブロックからThrowApplicationException方法を呼ぶ建設者を定義する。
CodeConstructor constructor1 = new CodeConstructor();
constructor1.Attributes = MemberAttributes.Public;
type1.Members.Add( constructor1 );
// Defines a try statement that calls the ThrowApplicationException method.
// ThrowApplicationException方法を呼ぶ試みステートメントを定義する。
CodeTryCatchFinallyStatement try1 = new CodeTryCatchFinallyStatement();
try1.TryStatements.Add(
new CodeMethodInvokeExpression(
new CodeThisReferenceExpression(),
"ThrowApplicationException"
)
);
constructor1.Statements.Add( try1 );
// Defines a catch clause for exceptions of type ApplicationException.
// タイプApplicationExceptionの例外のための捕獲物条項を定義する。
CodeCatchClause catch1 =
new CodeCatchClause(
"ex",
new CodeTypeReference(
"System.ApplicationException"
)
);
catch1.Statements.Add(
new CodeCommentStatement(
"Handle any System.ApplicationException here."
)
);
try1.CatchClauses.Add( catch1 );
// Defines a catch clause for any remaining unhandled exception types.
// どのような残留扱われていない例外タイプのための捕獲物条項でも定義する。
CodeCatchClause catch2 =
new CodeCatchClause(
"ex"
);
catch2.Statements.Add(
new CodeCommentStatement(
"Handle any other exception type here."
)
);
try1.CatchClauses.Add( catch2 );
// Defines a finally block by adding to the FinallyStatements collection.
// FinallyStatementsコレクションに追加して最終的なブロックを定義する。
try1.FinallyStatements.Add(
new CodeCommentStatement(
"Handle any finally block statements."
)
);
// A C# code generator produces the following source code for the preceeding example code:
// A C#コードジェネレータはpreceeding例コードのための以下のソースコードを作り出す:
// public class TryCatchTest
// {
//
// public TryCatchTest()
// {
// try
// {
// this.ThrowApplicationException();
// }
// catch (System.ApplicationException ex)
// {
// // Handle any System.ApplicationException here.
// }
// catch (System.Exception ex)
// {
// // Handle any other exception type here.
// }
// finally {
// // Handle any finally block statements.
// }
// }
//
// private void ThrowApplicationException()
// {
// throw new System.ApplicationException("Test Application Exception");
// }
// }
定義
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeTryCatchFinallyStatement : System.CodeDom.CodeStatement
クラス
#region アセンブリ System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// C:¥Program Files (x86)¥Reference Assemblies¥Microsoft¥Framework¥.NETFramework¥v4.6.1¥System.dll
#endregion
using System.Runtime.InteropServices;
namespace System.CodeDom
{
//
// 概要:
// 表す、 try ブロックの任意の数を catch 句と、オプションで、 finally ブロックします。
[ClassInterface( ClassInterfaceType.AutoDispatch )]
[ComVisible( true )]
public class CodeTryCatchFinallyStatement : CodeStatement
{
//
// 概要:
// System.CodeDom.CodeTryCatchFinallyStatement クラスの新しいインスタンスを初期化します。
public CodeTryCatchFinallyStatement();
//
// 概要:
// 新しいインスタンスを初期化、 System.CodeDom.CodeTryCatchFinallyStatement クラス一度実行するために指定されたステートメントを使用して、catch
// 句。
//
// パラメーター:
// tryStatements:
// 配列 System.CodeDom.CodeStatement を試すには、ステートメントを示すオブジェクト。
//
// catchClauses:
// 配列 System.CodeDom.CodeCatchClause catch 句を示すオブジェクト。
public CodeTryCatchFinallyStatement( CodeStatement[] tryStatements, CodeCatchClause[] catchClauses );
//
// 概要:
// 新しいインスタンスを初期化、 System.CodeDom.CodeTryCatchFinallyStatement クラスの指定されたステートメントを使用して、一度実行するため、句、および最後にステートメントをキャッチします。
//
// パラメーター:
// tryStatements:
// 配列 System.CodeDom.CodeStatement を試すには、ステートメントを示すオブジェクト。
//
// catchClauses:
// 配列 System.CodeDom.CodeCatchClause catch 句を示すオブジェクト。
//
// finallyStatements:
// 配列 System.CodeDom.CodeStatement オブジェクトを示す、最後を使用してステートメントです。
public CodeTryCatchFinallyStatement( CodeStatement[] tryStatements, CodeCatchClause[] catchClauses, CodeStatement[] finallyStatements );
//
// 概要:
// 試すには、ステートメントを取得します。
//
// 戻り値:
// A System.CodeDom.CodeStatementCollection を示すステートメントを実行してください。
public CodeStatementCollection TryStatements
{
get;
}
//
// 概要:
// 使用する catch 句を取得します。
//
// 戻り値:
// A System.CodeDom.CodeCatchClauseCollection を示す catch 句を使用します。
public CodeCatchClauseCollection CatchClauses
{
get;
}
//
// 概要:
// 取得、使用するステートメントを最後にします。
//
// 戻り値:
// A System.CodeDom.CodeStatementCollection を示す、finally ステートメントです。
public CodeStatementCollection FinallyStatements
{
get;
}
}
}