DivideByZeroException クラス

定義

整数または Decimal 値を 0 で除算しようとするとスローされる例外。

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
継承
DivideByZeroException
継承
属性

次の例では、整数除算で例外を DivideByZeroException 処理します。

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.
open System

let number1 = 3000
let number2 = 0
try
    printfn $"{number1 / number2}"
with :? DivideByZeroException ->
    printfn $"Division of {number1} by zero."

// 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.

注釈

整数または Decimal 数値を 0 で除算しようとすると、例外が DivideByZeroException スローされます。 例外を回避するには、整数または Decimal 値を持つ除算演算の分母が 0 以外であることを確認します。

浮動小数点値を 0 で除算しても例外はスローされません。IEEE 754 算術の規則に従って、正の無限大、負の無限大、または数値 (NaN) は発生しません。 次の例では整数除算ではなく浮動小数点除算を使用するため、操作は例外を DivideByZeroException スローしません。

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
open System

let number1 = 3000.
let number2 = 0.

printfn $"{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

詳細については、次のトピックを参照してください。 Single および Double

次の Microsoft Intermediate Language (MSIL) 命令は、次のようにスロー DivideByZeroExceptionします。

  • div

  • div.un

  • rem

  • rem.un

DivideByZeroException は、0x80020012値を持つ HRESULT COR_E_DIVIDEBYZEROを使用します。

インスタンスの初期プロパティ値の一覧についてはDivideByZeroExceptionを参照してください、DivideByZeroExceptionコンス トラクター。

コンストラクター

DivideByZeroException()

DivideByZeroException クラスの新しいインスタンスを初期化します。

DivideByZeroException(SerializationInfo, StreamingContext)

シリアル化したデータを使用して、DivideByZeroException クラスの新しいインスタンスを初期化します。

DivideByZeroException(String)

指定したエラー メッセージを使用して、DivideByZeroException クラスの新しいインスタンスを初期化します。

DivideByZeroException(String, Exception)

指定したエラー メッセージおよびこの例外の原因となった内部例外への参照を使用して、DivideByZeroException クラスの新しいインスタンスを初期化します。

プロパティ

Data

例外に関する追加のユーザー定義情報を提供する、キーと値のペアのコレクションを取得します。

(継承元 Exception)
HelpLink

この例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。

(継承元 Exception)
HResult

特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。

(継承元 Exception)
InnerException

現在の例外の原因となる Exception インスタンスを取得します。

(継承元 Exception)
Message

現在の例外を説明するメッセージを取得します。

(継承元 Exception)
Source

エラーの原因となるアプリケーションまたはオブジェクトの名前を取得または設定します。

(継承元 Exception)
StackTrace

呼び出し履歴で直前のフレームの文字列形式を取得します。

(継承元 Exception)
TargetSite

現在の例外がスローされたメソッドを取得します。

(継承元 Exception)

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetBaseException()

派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の根本原因である Exception を返します。

(継承元 Exception)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetObjectData(SerializationInfo, StreamingContext)

派生クラスでオーバーライドされた場合は、その例外に関する情報を使用して SerializationInfo を設定します。

(継承元 Exception)
GetType()

現在のインスタンスのランタイム型を取得します。

(継承元 Exception)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在の例外の文字列形式を作成して返します。

(継承元 Exception)

events

SerializeObjectState
互換性のために残されています。

例外がシリアル化され、例外に関するシリアル化されたデータを含む例外状態オブジェクトが作成されたときに発生します。

(継承元 Exception)

適用対象

こちらもご覧ください