Freigeben über


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 eines CodeThrowExceptionStatement neuen System.ExceptionVorgangs veranschaulicht.

// 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 Instanz eines Typs sein, der von der Exception Klasse abgeleitet ist.

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

Konstruktoren

Name Beschreibung
CodeThrowExceptionStatement()

Initialisiert eine neue Instanz der CodeThrowExceptionStatement-Klasse.

CodeThrowExceptionStatement(CodeExpression)

Initialisiert eine neue Instanz der CodeThrowExceptionStatement Klasse mit der angegebenen Ausnahmetypinstanz.

Eigenschaften

Name Beschreibung
EndDirectives

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

(Geerbt von CodeStatement)
LinePragma

Ruft die Zeile ab, in der die Code-Anweisung auftritt, oder legt sie fest.

(Geerbt von CodeStatement)
StartDirectives

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

(Geerbt von CodeStatement)
ToThrow

Ruft die auszuwerfende Ausnahme ab oder legt sie fest.

UserData

Ruft die vom Benutzer definierbaren Daten für das aktuelle Objekt ab.

(Geerbt von CodeObject)

Methoden

Name Beschreibung
Equals(Object)

Bestimmt, ob das angegebene Objekt dem aktuellen Objekt entspricht.

(Geerbt von Object)
GetHashCode()

Dient als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft die Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
ToString()

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

(Geerbt von Object)

Gilt für: