CodeThrowExceptionStatement-Klasse
Stellt eine Anweisung dar, die eine Ausnahme auslöst.
Namespace: System.CodeDom
Assembly: System (in system.dll)
Syntax
'Declaration
<SerializableAttribute> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class CodeThrowExceptionStatement
Inherits CodeStatement
'Usage
Dim instance As CodeThrowExceptionStatement
[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeThrowExceptionStatement : CodeStatement
[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[ComVisibleAttribute(true)]
public ref class CodeThrowExceptionStatement : public CodeStatement
/** @attribute SerializableAttribute() */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
/** @attribute ComVisibleAttribute(true) */
public class CodeThrowExceptionStatement extends CodeStatement
SerializableAttribute
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
ComVisibleAttribute(true)
public class CodeThrowExceptionStatement extends CodeStatement
Hinweise
Mit CodeThrowExceptionStatement kann eine Anweisung dargestellt werden, die eine Ausnahme auslöst. Bei dem Ausdruck muss es sich um einen Verweis auf eine Instanz eines Typs handeln, der von der Exception-Klasse abgeleitet wird, oder der Ausdruck muss als solcher ausgewertet werden.
Die ToThrow-Eigenschaft gibt die auszulösende Ausnahme an.
Beispiel
In diesem Beispiel wird veranschaulicht, wie mit einem CodeThrowExceptionStatement eine neue System.Exception ausgelöst wird.
' 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
// 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.
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(System.Exception.class.ToType()),
// parameters parameter indicates the constructor parameters.
new CodeExpression[]{}));
// A VJ# code generator produces the following source code for
// the preceeding example code:
// throw new System.Exception();
Vererbungshierarchie
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeThrowExceptionStatement
Threadsicherheit
Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0