Compartilhar via


CodeThrowExceptionStatement Classe

Definição

Representa uma instrução que gera uma exceção.

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
Herança
CodeThrowExceptionStatement
Atributos

Exemplos

Este exemplo demonstra como usar um CodeThrowExceptionStatement para lançar um novo 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

Comentários

CodeThrowExceptionStatement pode representar uma instrução que gera uma exceção. A expressão deve ser, ou avaliar, uma referência a uma instância de um tipo que deriva da Exception classe.

A ToThrow propriedade especifica a exceção a ser lançada.

Construtores

Nome Description
CodeThrowExceptionStatement()

Inicializa uma nova instância da classe CodeThrowExceptionStatement.

CodeThrowExceptionStatement(CodeExpression)

Inicializa uma nova instância da CodeThrowExceptionStatement classe com a instância de tipo de exceção especificada.

Propriedades

Nome Description
EndDirectives

Obtém um CodeDirectiveCollection objeto que contém diretivas finais.

(Herdado de CodeStatement)
LinePragma

Obtém ou define a linha na qual a instrução de código ocorre.

(Herdado de CodeStatement)
StartDirectives

Obtém um CodeDirectiveCollection objeto que contém diretivas de início.

(Herdado de CodeStatement)
ToThrow

Obtém ou define a exceção a ser lançada.

UserData

Obtém os dados definíveis do usuário para o objeto atual.

(Herdado de CodeObject)

Métodos

Nome Description
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Objectatual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a