DivideByZeroException 클래스

정의

정수나 Decimal 값을 0으로 나누려 할 때 throw되는 예외입니다.

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 throw하지 않습니다.

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

자세한 내용은 SingleDouble를 참조하세요.

다음 msIL(Microsoft 중간 언어) 지침은 을 throwDivideByZeroException합니다.

  • div

  • div.un

  • rem

  • rem.un

DivideByZeroException 는 값이 0x80020012 HRESULT COR_E_DIVIDEBYZERO 사용합니다.

인스턴스의 초기 속성 값의 목록을 DivideByZeroException, 참조는 DivideByZeroException 생성자입니다.

생성자

DivideByZeroException()

DivideByZeroException 클래스의 새 인스턴스를 초기화합니다.

DivideByZeroException(SerializationInfo, StreamingContext)

serialize된 데이터를 사용하여 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

현재 예외를 throw하는 메서드를 가져옵니다.

(다음에서 상속됨 Exception)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetBaseException()

파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다.

(다음에서 상속됨 Exception)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetObjectData(SerializationInfo, StreamingContext)

파생 클래스에서 재정의된 경우 예외에 관한 정보를 SerializationInfo 에 설정합니다.

(다음에서 상속됨 Exception)
GetType()

현재 인스턴스의 런타임 형식을 가져옵니다.

(다음에서 상속됨 Exception)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 예외에 대한 문자열 표현을 만들고 반환합니다.

(다음에서 상속됨 Exception)

이벤트

SerializeObjectState
사용되지 않음.

예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다.

(다음에서 상속됨 Exception)

적용 대상

추가 정보