DivideByZeroException Classe
Définition
public ref class DivideByZeroException : ArithmeticException
public class DivideByZeroException : ArithmeticException
[System.Serializable]
public class DivideByZeroException : ArithmeticException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class DivideByZeroException : ArithmeticException
type DivideByZeroException = class
inherit ArithmeticException
[<System.Serializable>]
type DivideByZeroException = class
inherit ArithmeticException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DivideByZeroException = class
inherit ArithmeticException
Public Class DivideByZeroException
Inherits ArithmeticException
- Héritage
- Héritage
- Attributs
Exemples
L’exemple suivant gère une DivideByZeroException exception dans la Division d’entiers.The following example handles a DivideByZeroException exception in integer division.
using System;
public class Example
{
public static void Main()
{
int number1 = 3000;
int number2 = 0;
try {
Console.WriteLine(number1 / number2);
}
catch (DivideByZeroException) {
Console.WriteLine("Division of {0} by zero.", number1);
}
}
}
// The example displays the following output:
// Division of 3000 by zero.
Module Example
Public Sub Main()
Dim number1 As Integer = 3000
Dim number2 As Integer = 0
Try
Console.WriteLine(number1\number2)
Catch e As DivideByZeroException
Console.WriteLine("Division of {0} by zero.", number1)
End Try
End Sub
End Module
' The example displays the following output:
' Division of 3000 by zero.
Remarques
Si vous tentez de diviser un entier ou un Decimal nombre par zéro, une exception est levée DivideByZeroException .Trying to divide an integer or Decimal number by zero throws a DivideByZeroException exception. Pour éviter l’exception, assurez-vous que le dénominateur d’une opération de division avec des valeurs entières ou Decimal n’est pas égal à zéro.To prevent the exception, ensure that the denominator in a division operation with integer or Decimal values is non-zero.
La Division d’une valeur à virgule flottante par zéro ne lève pas d’exception. Il en résulte un infini positif, un infini négatif ou une valeur non numérique (NaN), en fonction des règles de l’arithmétique IEEE 754.Dividing a floating-point value by zero doesn't throw an exception; it results in positive infinity, negative infinity, or not a number (NaN), according to the rules of IEEE 754 arithmetic. Étant donné que l’exemple suivant utilise la Division à virgule flottante plutôt que la Division d’entier, l’opération ne lève pas d' DivideByZeroException exception.Because the following example uses floating-point division rather than integer division, the operation does not throw a DivideByZeroException exception.
using System;
public class Example
{
public static void Main()
{
int number1 = 3000;
int number2 = 0;
Console.WriteLine((double)number1 / number2);
}
}
// The example displays the following output:
// Infinity
Module Example
Public Sub Main()
Dim number1 As Integer = 3000
Dim number2 As Integer = 0
Console.WriteLine(number1/number2)
End Sub
End Module
' The example displays the following output:
' Infinity
Pour plus d’informations, consultez Single et Double.For more information, see Single and Double.
Les instructions MSIL (Microsoft Intermediate Language) suivantes lèvent DivideByZeroException :The following Microsoft intermediate language (MSIL) instructions throw DivideByZeroException:
divdiv
div. undiv.un
remrem
REM. unrem.un
DivideByZeroException utilise le COR_E_DIVIDEBYZERO HRESULT, qui a la valeur 0x80020012.DivideByZeroException uses the HRESULT COR_E_DIVIDEBYZERO, which has the value 0x80020012.
Pour obtenir la liste des valeurs initiales des propriétés d’une instance de DivideByZeroException, consultez le DivideByZeroException constructeurs.For a list of initial property values for an instance of DivideByZeroException, see the DivideByZeroException constructors.
Constructeurs
DivideByZeroException() |
Initialise une nouvelle instance de la classe DivideByZeroException.Initializes a new instance of the DivideByZeroException class. |
DivideByZeroException(SerializationInfo, StreamingContext) |
Initialise une nouvelle instance de la classe DivideByZeroException avec des données sérialisées.Initializes a new instance of the DivideByZeroException class with serialized data. |
DivideByZeroException(String) |
Initialise une nouvelle instance de la classe DivideByZeroException avec un message d'erreur spécifié.Initializes a new instance of the DivideByZeroException class with a specified error message. |
DivideByZeroException(String, Exception) |
Initialise une nouvelle instance de la classe DivideByZeroException avec un message d'erreur spécifié et une référence à l'exception interne ayant provoqué cette exception.Initializes a new instance of the DivideByZeroException class with a specified error message and a reference to the inner exception that is the cause of this exception. |
Propriétés
Data |
Obtient une collection de paires clé/valeur qui fournissent des informations définies par l'utilisateur supplémentaires sur l'exception.Gets a collection of key/value pairs that provide additional user-defined information about the exception. (Hérité de Exception) |
HelpLink |
Obtient ou définit un lien vers le fichier d'aide associé à cette exception.Gets or sets a link to the help file associated with this exception. (Hérité de Exception) |
HResult |
Obtient ou définit HRESULT, valeur numérique codée qui est assignée à une exception spécifique.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Hérité de Exception) |
InnerException |
Obtient l'instance Exception qui a provoqué l'exception actuelle.Gets the Exception instance that caused the current exception. (Hérité de Exception) |
Message |
Obtient un message qui décrit l'exception active.Gets a message that describes the current exception. (Hérité de Exception) |
Source |
Obtient ou définit le nom de l'application ou de l'objet qui est à l'origine de l'erreur.Gets or sets the name of the application or the object that causes the error. (Hérité de Exception) |
StackTrace |
Obtient une représentation sous forme de chaîne des frames immédiats sur la pile des appels.Gets a string representation of the immediate frames on the call stack. (Hérité de Exception) |
TargetSite |
Obtient la méthode qui lève l'exception actuelle.Gets the method that throws the current exception. (Hérité de Exception) |
Méthodes
Equals(Object) |
Détermine si l'objet spécifié est égal à l'objet actuel.Determines whether the specified object is equal to the current object. (Hérité de Object) |
GetBaseException() |
En cas de substitution dans une classe dérivée, retourne la Exception qui est à l'origine d'une ou de plusieurs exceptions ultérieures.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (Hérité de Exception) |
GetHashCode() |
Fait office de fonction de hachage par défaut.Serves as the default hash function. (Hérité de Object) |
GetObjectData(SerializationInfo, StreamingContext) |
En cas de substitution dans une classe dérivée, définit SerializationInfo avec des informations sur l'exception.When overridden in a derived class, sets the SerializationInfo with information about the exception. (Hérité de Exception) |
GetType() |
Obtient le type au moment de l'exécution de l'instance actuelle.Gets the runtime type of the current instance. (Hérité de Exception) |
MemberwiseClone() |
Crée une copie superficielle du Object actuel.Creates a shallow copy of the current Object. (Hérité de Object) |
ToString() |
Crée et retourne une chaîne représentant l'exception actuelle.Creates and returns a string representation of the current exception. (Hérité de Exception) |
Événements
SerializeObjectState |
Se produit quand une exception est sérialisée pour créer un objet d'état d'exception qui contient des données sérialisées concernant l'exception.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Hérité de Exception) |