CodeThrowExceptionStatement Class
Represents a statement that throws an exception.
For a list of all members of this type, see CodeThrowExceptionStatement Members.
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeThrowExceptionStatement
[Visual Basic] <Serializable> <ClassInterface(ClassInterfaceType.AutoDispatch)> <ComVisible(True)> Public Class CodeThrowExceptionStatement Inherits CodeStatement [C#] [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] public class CodeThrowExceptionStatement : CodeStatement [C++] [Serializable] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ComVisible(true)] public __gc class CodeThrowExceptionStatement : public CodeStatement [JScript] public Serializable ClassInterface(ClassInterfaceType.AutoDispatch) ComVisible(true) class CodeThrowExceptionStatement extends CodeStatement
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
CodeThrowExceptionStatement can represent a statement that throws an exception. The expression should be, or evaluate to, a reference to an instance of a type that derives from the Exception class.
The ToThrow property specifies the exception to throw.
Example
[Visual Basic, C#, C++] This example demonstrates using a CodeThrowExceptionStatement to throw a new System.Exception.
[Visual Basic] ' 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 [C#] // 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(); [C++] // This CodeThrowExceptionStatement throws a new System.Exception. CodeExpression* temp0 []; 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. temp0 ) ); // A C# code generator produces the following source code for the preceeding example code: // throw new System.Exception();
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.CodeDom
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
See Also
CodeThrowExceptionStatement Members | System.CodeDom Namespace