double.Parse will throw an exception if the input is not valid. So you either need to use try catch - or the preferred way would be to use double.TryParse as below. The value of y below will be set to the value if TryParse returns true.
class Program
{
static void Main(string[] args)
{
// This will cause an exception
var someString = "SomeValue";
var x = double.Parse(someString); // Comment this line out to run this example
// This will work
double y;
if (double.TryParse(someString, out y))
{
Console.WriteLine(someString + " is a valid decimal");
}
else
{
Console.WriteLine(someString + " is not a valid decimal");
}
someString = "14.7";
if (double.TryParse(someString, out y))
{
Console.WriteLine(someString + " is a valid decimal");
}
else
{
Console.WriteLine(someString + " is not a valid decimal");
}
}
}