Convert double to integer and catch OverflowException in CSharp
Description
The following code shows how to convert double to integer and catch OverflowException.
Example
using System;//from www . j a v a 2 s. c om
using System.Globalization;
public class Example
{
public static void Main()
{
double dbl2 = 999111111188811.999D;
try
{
int number2 = (int)dbl2;
Console.WriteLine(number2);
}
catch (OverflowException)
{
Console.WriteLine("{0} is out of range of an Int32.", dbl2);
}
}
}
The code above generates the following result.