CodeThrowExceptionStatement Класс
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Представляет инструкцию, которая создает исключение.
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
- Наследование
- Атрибуты
Примеры
В этом примере показано, как создать CodeThrowExceptionStatement новый 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
Комментарии
CodeThrowExceptionStatement может представлять инструкцию, которая вызывает исключение. Выражение должно быть или оцениваться как ссылка на экземпляр типа, наследуемого Exception от класса.
Свойство ToThrow задает исключение для создания.
Конструкторы
| Имя | Описание |
|---|---|
| CodeThrowExceptionStatement() |
Инициализирует новый экземпляр класса CodeThrowExceptionStatement. |
| CodeThrowExceptionStatement(CodeExpression) |
Инициализирует новый экземпляр класса с указанным экземпляром CodeThrowExceptionStatement типа исключения. |
Свойства
| Имя | Описание |
|---|---|
| EndDirectives |
CodeDirectiveCollection Возвращает объект, содержащий конечные директивы. (Унаследовано от CodeStatement) |
| LinePragma |
Возвращает или задает строку, в которой происходит инструкция кода. (Унаследовано от CodeStatement) |
| StartDirectives |
CodeDirectiveCollection Возвращает объект, содержащий директивы start. (Унаследовано от CodeStatement) |
| ToThrow |
Возвращает или задает исключение для создания. |
| UserData |
Возвращает определяемые пользователем данные для текущего объекта. (Унаследовано от CodeObject) |
Методы
| Имя | Описание |
|---|---|
| Equals(Object) |
Определяет, равен ли указанный объект текущему объекту. (Унаследовано от Object) |
| GetHashCode() |
Служит хэш-функцией по умолчанию. (Унаследовано от Object) |
| GetType() |
Возвращает Type текущего экземпляра. (Унаследовано от Object) |
| MemberwiseClone() |
Создает неглубокую копию текущей Object. (Унаследовано от Object) |
| ToString() |
Возвращает строку, представляющую текущий объект. (Унаследовано от Object) |