本文整理匯總了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.