Partager via


CodeThrowExceptionStatement Classe

Définition

Représente une instruction qui lève une exception.

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
Héritage
CodeThrowExceptionStatement
Attributs

Exemples

Cet exemple illustre l’utilisation d’un CodeThrowExceptionStatement élément pour lever un nouveau 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

Remarques

CodeThrowExceptionStatement peut représenter une instruction qui lève une exception. L’expression doit être, ou évaluer, une référence à une instance d’un type qui dérive de la Exception classe.

La ToThrow propriété spécifie l’exception à lever.

Constructeurs

Nom Description
CodeThrowExceptionStatement()

Initialise une nouvelle instance de la classe CodeThrowExceptionStatement.

CodeThrowExceptionStatement(CodeExpression)

Initialise une nouvelle instance de la CodeThrowExceptionStatement classe avec l’instance de type d’exception spécifiée.

Propriétés

Nom Description
EndDirectives

Obtient un CodeDirectiveCollection objet qui contient des directives de fin.

(Hérité de CodeStatement)
LinePragma

Obtient ou définit la ligne sur laquelle l’instruction de code se produit.

(Hérité de CodeStatement)
StartDirectives

Obtient un CodeDirectiveCollection objet qui contient des directives de début.

(Hérité de CodeStatement)
ToThrow

Obtient ou définit l’exception à lever.

UserData

Obtient les données définissables par l’utilisateur pour l’objet actuel.

(Hérité de CodeObject)

Méthodes

Nom Description
Equals(Object)

Détermine si l’objet spécifié est égal à l’objet actuel.

(Hérité de Object)
GetHashCode()

Sert de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient la Type de l’instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Objectactuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l’objet actuel.

(Hérité de Object)

S’applique à