CodeThrowExceptionStatement Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Representerar en instruktion som utlöser ett undantag.
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
- Arv
- Attribut
Exempel
Det här exemplet visar hur du använder en CodeThrowExceptionStatement för att skapa en ny 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
Kommentarer
CodeThrowExceptionStatement kan representera en instruktion som utlöser ett undantag. Uttrycket ska vara, eller utvärdera till, en referens till en instans av en typ som härleds från Exception klassen.
Egenskapen ToThrow anger undantaget som ska utlösas.
Konstruktorer
| Name | Description |
|---|---|
| CodeThrowExceptionStatement() |
Initierar en ny instans av CodeThrowExceptionStatement klassen. |
| CodeThrowExceptionStatement(CodeExpression) |
Initierar en ny instans av CodeThrowExceptionStatement klassen med den angivna undantagstypsinstansen. |
Egenskaper
| Name | Description |
|---|---|
| EndDirectives |
Hämtar ett CodeDirectiveCollection objekt som innehåller slutdirektiv. (Ärvd från CodeStatement) |
| LinePragma |
Hämtar eller anger den rad där kodsatsen inträffar. (Ärvd från CodeStatement) |
| StartDirectives |
Hämtar ett CodeDirectiveCollection objekt som innehåller startdirektiv. (Ärvd från CodeStatement) |
| ToThrow |
Hämtar eller anger undantaget som ska utlösas. |
| UserData |
Hämtar användardefinierbara data för det aktuella objektet. (Ärvd från CodeObject) |
Metoder
| Name | Description |
|---|---|
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |