CodeCatchClause クラス
アセンブリ: System (system.dll 内)

<SerializableAttribute> _ <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ <ComVisibleAttribute(True)> _ Public Class CodeCatchClause
[SerializableAttribute] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] [ComVisibleAttribute(true)] public class CodeCatchClause
[SerializableAttribute] [ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] [ComVisibleAttribute(true)] public ref class CodeCatchClause

CodeCatchClause を使用して、try/catch ステートメントの catch 例外ブロックを表すことができます。
CatchExceptionType プロパティは、キャッチする例外の型を指定します。LocalName プロパティは、キャッチされる例外を表す変数の名前を指定します。Statements コレクション プロパティには、catch ブロックに対応するステートメントが格納されます。

CodeCatchClause オブジェクトを使用して、try...catch ブロックの例外処理句を定義する方法については、次のコード例を参照してください。
' Declares a type to contain a try...catch block. Dim type1 As New CodeTypeDeclaration("TryCatchTest") ' Defines a method that throws an exception of type System.ApplicationException. Dim method1 As 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. Dim constructor1 As New CodeConstructor() constructor1.Attributes = MemberAttributes.Public type1.Members.Add(constructor1) ' Defines a try statement that calls the ThrowApplicationException method. Dim try1 As New CodeTryCatchFinallyStatement() try1.TryStatements.Add(New CodeMethodInvokeExpression(New CodeThisReferenceExpression(), "ThrowApplicationException")) constructor1.Statements.Add(try1) ' Defines a catch clause for exceptions of type ApplicationException. Dim catch1 As 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. Dim catch2 As 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. try1.FinallyStatements.Add(New CodeCommentStatement("Handle any finally block statements.")) ' A Visual Basic code generator produces the following source code for the preceeding example code: ' 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"); ' } ' }
// Declares a type to contain a try...catch block. CodeTypeDeclaration type1 = new CodeTypeDeclaration("TryCatchTest"); // Defines a method that throws an exception of type 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. CodeConstructor constructor1 = new CodeConstructor(); constructor1.Attributes = MemberAttributes.Public; type1.Members.Add( constructor1 ); // Defines a try statement that calls the ThrowApplicationException method. 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. 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. try1.FinallyStatements.Add( new CodeCommentStatement("Handle any finally block statements.") ); // A C# code generator produces the following source code for the preceeding example code: // 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"); // } // }
// Declares a type to contain a try...catch block. CodeTypeDeclaration^ type1 = gcnew CodeTypeDeclaration( "TryCatchTest" ); // Defines a method that throws an exception of type System.ApplicationException. CodeMemberMethod^ method1 = gcnew CodeMemberMethod; method1->Name = "ThrowApplicationException"; array<CodePrimitiveExpression^>^temp = {gcnew CodePrimitiveExpression( "Test Application Exception" )}; method1->Statements->Add( gcnew CodeThrowExceptionStatement( gcnew CodeObjectCreateExpression( "System.ApplicationException",temp ) ) ); type1->Members->Add( method1 ); // Defines a constructor that calls the ThrowApplicationException method from a try block. CodeConstructor^ constructor1 = gcnew CodeConstructor; constructor1->Attributes = MemberAttributes::Public; type1->Members->Add( constructor1 ); // Defines a try statement that calls the ThrowApplicationException method. CodeTryCatchFinallyStatement^ try1 = gcnew CodeTryCatchFinallyStatement; try1->TryStatements->Add( gcnew CodeMethodInvokeExpression( gcnew CodeThisReferenceExpression,"ThrowApplicationException", nullptr ) ); constructor1->Statements->Add( try1 ); // Defines a catch clause for exceptions of type ApplicationException. CodeCatchClause^ catch1 = gcnew CodeCatchClause( "ex",gcnew CodeTypeReference( "System.ApplicationException" ) ); catch1->Statements->Add( gcnew CodeCommentStatement( "Handle any System.ApplicationException here." ) ); try1->CatchClauses->Add( catch1 ); // Defines a catch clause for any remaining unhandled exception types. CodeCatchClause^ catch2 = gcnew CodeCatchClause( "ex" ); catch2->Statements->Add( gcnew CodeCommentStatement( "Handle any other exception type here." ) ); try1->CatchClauses->Add( catch2 ); // Defines a finally block by adding to the FinallyStatements collection. try1->FinallyStatements->Add( gcnew CodeCommentStatement( "Handle any finally block statements." ) ); // A C# code generator produces the following source code for the preceeding example code: // 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"); // } // }
// Declares a type to contain a try...catch block. CodeTypeDeclaration type1 = new CodeTypeDeclaration("TryCatchTest"); // Defines a method that throws an exception of type // System.ApplicationException. CodeMemberMethod method1 = new CodeMemberMethod(); method1.set_Name("ThrowApplicationException"); method1.get_Statements().Add(new CodeThrowExceptionStatement(new CodeObjectCreateExpression( "System.ApplicationException", new CodeExpression[] { new CodePrimitiveExpression("Test Application Exception") }))); type1.get_Members().Add(method1); // Defines a constructor that calls the ThrowApplicationException // method from a try block. CodeConstructor constructor1 = new CodeConstructor(); constructor1.set_Attributes(MemberAttributes.Public); type1.get_Members().Add(constructor1); // Defines a try statement that calls the // ThrowApplicationException method. CodeTryCatchFinallyStatement try1 = new CodeTryCatchFinallyStatement(); try1.get_TryStatements().Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "ThrowApplicationException", new CodeExpression[] {})); constructor1.get_Statements().Add(try1); // Defines a catch clause for exceptions of type ApplicationException. CodeCatchClause catch1 = new CodeCatchClause("ex", new CodeTypeReference("System.ApplicationException")); catch1.get_Statements().Add(new CodeCommentStatement( "Handle any System.ApplicationException here.")); try1.get_CatchClauses().Add(catch1); // Defines a catch clause for any remaining unhandled exception types. CodeCatchClause catch2 = new CodeCatchClause("ex"); catch2.get_Statements().Add(new CodeCommentStatement( "Handle any other exception type here.")); try1.get_CatchClauses().Add(catch2); // Defines a finally block by adding to the FinallyStatements collection. try1.get_FinallyStatements().Add(new CodeCommentStatement( "Handle any finally block statements.")); // A VJ# code generator produces the following source code for the // preceeding example code: // 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.CodeDom.CodeCatchClause


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CodeCatchClause コンストラクタ ()
アセンブリ: System (system.dll 内)


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CodeCatchClause コンストラクタ (String, CodeTypeReference)
アセンブリ: System (system.dll 内)

Dim localName As String Dim catchExceptionType As CodeTypeReference Dim instance As New CodeCatchClause(localName, catchExceptionType)

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CodeCatchClause コンストラクタ (String)
アセンブリ: System (system.dll 内)


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CodeCatchClause クラス
CodeCatchClause メンバ
System.CodeDom 名前空間
CodeParameterDeclarationExpression
CodeStatement
CodeCatchClause コンストラクタ

名前 | 説明 |
---|---|
CodeCatchClause () | CodeCatchClause クラスの新しいインスタンスを初期化します。 |
CodeCatchClause (String) | 例外のローカル変数名を指定して、CodeCatchClause クラスの新しいインスタンスを初期化します。 |
CodeCatchClause (String, CodeTypeReference) | 例外のローカル変数名と例外の種類を指定して、CodeCatchClause クラスの新しいインスタンスを初期化します。 |
CodeCatchClause (String, CodeTypeReference, CodeStatement[]) | 例外のローカル変数名、例外の種類、およびステートメント コレクションを指定して、CodeCatchClause クラスの新しいインスタンスを初期化します。 |

CodeCatchClause コンストラクタ (String, CodeTypeReference, CodeStatement[])
アセンブリ: System (system.dll 内)

Public Sub New ( _ localName As String, _ catchExceptionType As CodeTypeReference, _ ParamArray statements As CodeStatement() _ )
Dim localName As String Dim catchExceptionType As CodeTypeReference Dim statements As CodeStatement() Dim instance As New CodeCatchClause(localName, catchExceptionType, statements)
public CodeCatchClause ( string localName, CodeTypeReference catchExceptionType, params CodeStatement[] statements )
public: CodeCatchClause ( String^ localName, CodeTypeReference^ catchExceptionType, ... array<CodeStatement^>^ statements )
public CodeCatchClause ( String localName, CodeTypeReference catchExceptionType, CodeStatement[] statements )
public function CodeCatchClause ( localName : String, catchExceptionType : CodeTypeReference, ... statements : CodeStatement[] )

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CodeCatchClause プロパティ

名前 | 説明 | |
---|---|---|
![]() | CatchExceptionType | catch ブロックで処理される例外の型を取得または設定します。 |
![]() | LocalName | catch 句で処理する例外の変数名を取得または設定します。 |
![]() | Statements | catch ブロック内で、ステートメントを取得します。 |

CodeCatchClause メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

CodeCatchClause メンバ
try/catch ステートメントの catch 例外ブロックを表します。
CodeCatchClause データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | CatchExceptionType | catch ブロックで処理される例外の型を取得または設定します。 |
![]() | LocalName | catch 句で処理する例外の変数名を取得または設定します。 |
![]() | Statements | catch ブロック内で、ステートメントを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

Weblioに収録されているすべての辞書からCodeCatchClauseを検索する場合は、下記のリンクをクリックしてください。

- CodeCatchClauseのページへのリンク