什么是OverflowException
就是溢出异常。这个一般是当在线程检查的上下文中执行的算术、强制转换或转换运算导致溢出时引发的异常。
- 继承
-
ObjectExceptionSystemExceptionArithmeticExceptionOverflowException
说明
-
OverflowException。
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.
-
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.