Condividi tramite


CodeThrowExceptionStatement Classe

Definizione

Rappresenta un'istruzione che genera un'eccezione.

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
Ereditarietà
CodeThrowExceptionStatement
Attributi

Esempio

In questo esempio viene illustrato l'uso di per CodeThrowExceptionStatement generare un nuovo System.Exceptionoggetto .

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

Commenti

CodeThrowExceptionStatement può rappresentare un'istruzione che genera un'eccezione. L'espressione deve essere o restituire un riferimento a un'istanza di un tipo che deriva dalla Exception classe .

La ToThrow proprietà specifica l'eccezione da generare.

Costruttori

Nome Descrizione
CodeThrowExceptionStatement()

Inizializza una nuova istanza della classe CodeThrowExceptionStatement.

CodeThrowExceptionStatement(CodeExpression)

Inizializza una nuova istanza della CodeThrowExceptionStatement classe con l'istanza del tipo di eccezione specificata.

Proprietà

Nome Descrizione
EndDirectives

Ottiene un CodeDirectiveCollection oggetto che contiene direttive end.

(Ereditato da CodeStatement)
LinePragma

Ottiene o imposta la riga in cui si verifica l'istruzione del codice.

(Ereditato da CodeStatement)
StartDirectives

Ottiene un CodeDirectiveCollection oggetto contenente le direttive start.

(Ereditato da CodeStatement)
ToThrow

Ottiene o imposta l'eccezione da generare.

UserData

Ottiene i dati definibili dall'utente per l'oggetto corrente.

(Ereditato da CodeObject)

Metodi

Nome Descrizione
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a