Share via


CodeThrowExceptionStatement Klasse

Definition

Stellt eine Anweisung dar, die eine Ausnahme auslöst.

public ref class CodeThrowExceptionStatement : System::CodeDom::CodeStatement
public class CodeThrowExceptionStatement : System.CodeDom.CodeStatement
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeThrowExceptionStatement : System.CodeDom.CodeStatement
type CodeThrowExceptionStatement = class
    inherit CodeStatement
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeThrowExceptionStatement = class
    inherit CodeStatement
Public Class CodeThrowExceptionStatement
Inherits CodeStatement
Vererbung
CodeThrowExceptionStatement
Attribute

Beispiele

In diesem Beispiel wird die Verwendung von CodeThrowExceptionStatement zum Auslösen einer neuen System.Exceptionveranschaulicht.

// 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

Hinweise

CodeThrowExceptionStatement kann eine Anweisung darstellen, die eine Ausnahme auslöst. Der Ausdruck sollte ein Verweis auf eine instance eines Typs sein, der von der Exception -Klasse abgeleitet ist.

Die ToThrow -Eigenschaft gibt die ausnahme an, die ausgelöst werden soll.

Konstruktoren

CodeThrowExceptionStatement()

Initialisiert eine neue Instanz der CodeThrowExceptionStatement-Klasse.

CodeThrowExceptionStatement(CodeExpression)

Initialisiert eine neue Instanz der CodeThrowExceptionStatement-Klasse unter Verwendung der angegebenen Ausnahmetypinstanz.

Eigenschaften

EndDirectives

Ruft ein CodeDirectiveCollection-Objekt ab, das Enddirektiven enthält.

(Geerbt von CodeStatement)
LinePragma

Ruft die Zeile ab, in der die Codeanweisung auftritt, oder legt diese fest.

(Geerbt von CodeStatement)
StartDirectives

Ruft ein CodeDirectiveCollection-Objekt ab, das Startdirektiven enthält.

(Geerbt von CodeStatement)
ToThrow

Ruft die auszulösende Ausnahme ab oder legt diese fest.

UserData

Ruft die benutzerdefinierbaren Daten für das aktuelle Objekt ab.

(Geerbt von CodeObject)

Methoden

Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
GetHashCode()

Fungiert als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft den Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Gilt für: