CodeThrowExceptionStatement CodeThrowExceptionStatement CodeThrowExceptionStatement CodeThrowExceptionStatement Class

定義

表示擲回例外狀況的陳述式。Represents a statement that throws an exception.

public ref class CodeThrowExceptionStatement : System::CodeDom::CodeStatement
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeThrowExceptionStatement : System.CodeDom.CodeStatement
type CodeThrowExceptionStatement = class
    inherit CodeStatement
Public Class CodeThrowExceptionStatement
Inherits CodeStatement
繼承
CodeThrowExceptionStatementCodeThrowExceptionStatementCodeThrowExceptionStatementCodeThrowExceptionStatement
屬性

範例

這個範例示範CodeThrowExceptionStatement如何使用來擲回新System.Exception的。This example demonstrates using a CodeThrowExceptionStatement to throw a new System.Exception.

// This CodeThrowExceptionStatement throws a new System.Exception.
array<CodeExpression^>^temp0;
CodeThrowExceptionStatement^ throwException = gcnew CodeThrowExceptionStatement( gcnew CodeObjectCreateExpression( gcnew CodeTypeReference( System::Exception::typeid ),temp0 ) );

// A C# code generator produces the following source code for the preceeding example code:
// throw new System.Exception();
// This CodeThrowExceptionStatement throws a new System.Exception.
CodeThrowExceptionStatement throwException = new CodeThrowExceptionStatement( 
    // codeExpression parameter indicates the exception to throw.
    // You must use an object create expression to new an exception here.
    new CodeObjectCreateExpression(
    // createType parameter inidicates the type of object to create.
    new CodeTypeReference(typeof(System.Exception)),
    // parameters parameter indicates the constructor parameters.
    new CodeExpression[] {} ) );

// A C# code generator produces the following source code for the preceeding example code:

// throw new System.Exception();
 ' This CodeThrowExceptionStatement throws a new System.Exception.
 ' The codeExpression parameter indicates the exception to throw.
 ' You must use an object create expression to new an exception here.
 Dim throwException As New CodeThrowExceptionStatement( _
New CodeObjectCreateExpression( _
    New CodeTypeReference(GetType(System.Exception)), _
    New CodeExpression() {}))

 ' A Visual Basic code generator produces the following source code for the preceeding example code:

 ' Throw New System.Exception

備註

CodeThrowExceptionStatement可以表示擲回例外狀況的語句。CodeThrowExceptionStatement can represent a statement that throws an exception. 運算式應為衍生自Exception類別之類型實例的參考, 或評估為。The expression should be, or evaluate to, a reference to an instance of a type that derives from the Exception class.

ToThrow屬性會指定要擲回的例外狀況。The ToThrow property specifies the exception to throw.

建構函式

CodeThrowExceptionStatement() CodeThrowExceptionStatement() CodeThrowExceptionStatement() CodeThrowExceptionStatement()

初始化 CodeThrowExceptionStatement 類別的新執行個體。Initializes a new instance of the CodeThrowExceptionStatement class.

CodeThrowExceptionStatement(CodeExpression) CodeThrowExceptionStatement(CodeExpression) CodeThrowExceptionStatement(CodeExpression) CodeThrowExceptionStatement(CodeExpression)

使用指定的例外狀況型別執行個體,初始化 CodeThrowExceptionStatement 類別的新執行個體。Initializes a new instance of the CodeThrowExceptionStatement class with the specified exception type instance.

屬性

EndDirectives EndDirectives EndDirectives EndDirectives

取得包含結尾指示詞的 CodeDirectiveCollection 物件。Gets a CodeDirectiveCollection object that contains end directives.

(Inherited from CodeStatement)
LinePragma LinePragma LinePragma LinePragma

取得或設定程式碼陳述式發生所在的行。Gets or sets the line on which the code statement occurs.

(Inherited from CodeStatement)
StartDirectives StartDirectives StartDirectives StartDirectives

取得包含開頭指示詞的 CodeDirectiveCollection 物件。Gets a CodeDirectiveCollection object that contains start directives.

(Inherited from CodeStatement)
ToThrow ToThrow ToThrow ToThrow

取得或設定要擲回的例外狀況。Gets or sets the exception to throw.

UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於