本文整理汇总了C#中System.OverflowException类的典型用法代码示例。如果您正苦于以下问题:C# OverflowException类的具体用法?C# OverflowException怎么用?C# OverflowException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OverflowException类属于System命名空间,在下文中一共展示了OverflowException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: catch
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);
} }
输出:
Exception: 6.084E+17 > 2.147484E+009.
示例2: catch
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);
} }
输出:
Exception: 241 > 127.
示例3: catch
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);
}
输出:
Converted the Byte value 241 to the SByte value -15.