OverflowException 클래스

정의

checked 컨텍스트의 산술, 캐스팅 또는 변환 연산으로 인해 오버플로가 발생하는 경우 throw되는 예외입니다.

public ref class OverflowException : ArithmeticException
public class OverflowException : ArithmeticException
[System.Serializable]
public class OverflowException : ArithmeticException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class OverflowException : ArithmeticException
type OverflowException = class
    inherit ArithmeticException
[<System.Serializable>]
type OverflowException = class
    inherit ArithmeticException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type OverflowException = class
    inherit ArithmeticException
Public Class OverflowException
Inherits ArithmeticException
상속
상속
특성

설명

런타임에 다음 조건에서 throw OverflowException 됩니다.

  • 산술 연산은 연산에서 반환된 데이터 형식의 범위를 벗어난 결과를 생성합니다. 다음 예제에서는 형식의 OverflowException 범위를 오버플로하는 곱하기 연산에 의해 throw되는 것을 보여 줍니다 Int32 .

    int value = 780000000;
    checked {
    try {
       // Square the original value.
       int square = value * value;
       Console.WriteLine("{0} ^ 2 = {1}", value, square);
    }
    catch (OverflowException) {
       double square = Math.Pow(value, 2);
       Console.WriteLine("Exception: {0} > {1:E}.",
                         square, Int32.MaxValue);
    } }
    // The example displays the following output:
    //       Exception: 6.084E+17 > 2.147484E+009.
    
    open Checked
    
    let v = 780000000
    try
       // Square the original value.
       let square = v * v
       printfn $"{v} ^ 2 = {square}"
    with :? OverflowException ->
        let square = float v ** 2
        printfn $"Exception: {square} > {Int32.MaxValue:E}."
    // The example displays the following output:
    //       Exception: 6.084E+17 > 2.147484E+009.
    
    Dim value As Integer = 780000000
    Try
       ' Square the original value.
       Dim square As Integer = value * value 
       Console.WriteLine("{0} ^ 2 = {1}", value, square)
    Catch e As OverflowException
       Dim square As Double = Math.Pow(value, 2)
       Console.WriteLine("Exception: {0} > {1:E}.", _
                         square, Int32.MaxValue)
    End Try
    ' The example displays the following output:
    '       Exception: 6.084E+17 > 2.147484E+009.
    
  • 캐스팅 또는 변환 작업은 축소 변환을 수행하려고 시도하며 원본 데이터 형식의 값이 대상 데이터 형식의 범위를 벗어났습니다. 다음 예제에서는 부호 없는 큰 바이트 값을 부호 있는 바이트 값으로 변환하려고 시도하여 throw되는 바이트를 보여 OverflowException 줍니다.

    byte value = 241;
    checked {
    try {
       sbyte newValue = (sbyte) value;
       Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                         value.GetType().Name, value,
                         newValue.GetType().Name, newValue);
    }
    catch (OverflowException) {
       Console.WriteLine("Exception: {0} > {1}.", value, SByte.MaxValue);
    } }
    // The example displays the following output:
    //       Exception: 241 > 127.
    
    open Checked
    
    let value = 241uy
    try
        let newValue = int8 value
        printfn $"Converted the {value.GetType().Name} value {value} to the {newValue.GetType().Name} value {newValue}."
    with :? OverflowException ->
        printfn $"Exception: {value} > {SByte.MaxValue}."
    // The example displays the following output:
    //       Exception: 241 > 127.
    
    Dim value As Byte = 241
    Try
       Dim newValue As SByte = (CSByte(value))
       Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.", _
                         value.GetType().Name, value, _
                         newValue.GetType().Name, newValue)
    Catch e As OverflowException
       Console.WriteLine("Exception: {0} > {1}.", value, SByte.MaxValue)
    End Try                            
    ' The example displays the following output:
    '       Exception: 241 > 127.
    

각 경우에 작업의 결과는 속성보다 MinValue 작거나 작업에서 발생하는 데이터 형식의 속성보다 MaxValue 큰 값입니다.

산술, 캐스팅 또는 변환 연산을 throw OverflowException하려면 선택된 컨텍스트에서 작업이 발생해야 합니다. 기본적으로 Visual Basic 산술 연산 및 오버플로가 선택됩니다. C# 및 F#에서는 그렇지 않습니다. 확인되지 않은 컨텍스트에서 작업이 발생하는 경우 대상 형식에 맞지 않는 상위 비트를 삭제하여 결과가 잘립니다. 다음 예제에서는 C# 또는 F#에서 이러한 확인되지 않은 변환을 보여 줍니다. 선택되지 않은 컨텍스트에서 이전 예제를 반복합니다.

byte value = 241;
try {
   sbyte newValue = (sbyte) value;
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                     value.GetType().Name, value,
                     newValue.GetType().Name, newValue);
}
catch (OverflowException) {
   Console.WriteLine("Exception: {0} > {1}.", value, SByte.MaxValue);
}
// The example displays the following output:
//       Converted the Byte value 241 to the SByte value -15.
let value = 241uy
try
    let newValue = int8 value
    printfn $"Converted the {value.GetType().Name} value {value} to the {newValue.GetType().Name} value {newValue}."
with :? OverflowException ->
    printfn $"Exception: {value} > {SByte.MaxValue}."
// The example displays the following output:
//       Converted the Byte value 241 to the SByte value -15.

다음 MSIL(Microsoft 중간 언어) 지침은 다음을 throw합니다 OverflowException.

  • add.ovf. <signed>

  • conv.ovf. <to type>

  • conv.ovf. <to type> .un

  • mul.ovf. <type>

  • sub.ovf. <type>

  • newarr

OverflowException 는 값이 0x80131516 HRESULT COR_E_OVERFLOW 사용합니다.

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

생성자

OverflowException()

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

OverflowException(SerializationInfo, StreamingContext)

serialize된 데이터를 사용하여 OverflowException 클래스의 새 인스턴스를 초기화합니다.

OverflowException(String)

지정된 오류 메시지를 사용하여 OverflowException 클래스의 새 인스턴스를 초기화합니다.

OverflowException(String, Exception)

지정된 오류 메시지와 해당 예외의 원인인 내부 예외에 대한 참조를 사용하여 OverflowException 클래스의 새 인스턴스를 초기화합니다.

속성

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)

적용 대상

추가 정보