CodeThrowExceptionStatement 类
本文内容
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示引发异常的语句。
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.
array<CodeExpression^>^temp0;
CodeThrowExceptionStatement^ throwException = gcnew CodeThrowExceptionStatement( gcnew CodeObjectCreateExpression( gcnew CodeTypeReference( System::Exception::typeid ),temp0 ) );
// 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.
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 指定要引发的异常。
Code |
初始化 CodeThrowExceptionStatement 类的新实例。 |
Code |
用指定的异常类型实例初始化 CodeThrowExceptionStatement 类的新实例。 |
End |
获取包含结束指令的 CodeDirectiveCollection 对象。 (继承自 CodeStatement) |
Line |
获取或设置代码语句所在的行。 (继承自 CodeStatement) |
Start |
获取包含开始指令的 CodeDirectiveCollection 对象。 (继承自 CodeStatement) |
To |
获取或设置要引发的异常。 |
User |
获取当前对象的用户可定义数据。 (继承自 CodeObject) |
Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
Get |
作为默认哈希函数。 (继承自 Object) |
Get |
获取当前实例的 Type。 (继承自 Object) |
Memberwise |
创建当前 Object 的浅表副本。 (继承自 Object) |
To |
返回表示当前对象的字符串。 (继承自 Object) |
产品 | 版本 |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |