Unfortunately this value is greater than double.MaxValue
, hence the exception.
As codekaizen suggests, you could hard-code a test for the string. A better (IMO) alternative if you're the one producing the string in the first place is to use the "r" format specifier. Then the string you produce will be "1.7976931348623157E+308" instead, which then parses correctly:
string s = double.MaxValue.ToString("r");
double d = double.Parse(s); // No exception
Obviously that's no help if you don't have control over the data - but then you should understand you're likely to be losing data already in that case.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…