double.Parse fails on NaN
In my 3.5 SP1 windows form application the following lines both fail with a format exception.
Double.Parse(double.NaN.ToString(CultureInfo.InvariantCulture),开发者_运维知识库CultureInfo.InvariantCulture);
Double.Parse(double.NaN.ToString());
What could be going on here?
Update:
The format exception only occurs when when you start the application from within Visual Studio (2010) and have the Common Language Runtime Exception notificaion (Debug->Exceptions...) enabled.
I think the exception is being thrown (and caught) within the .NET Framework itself. If you run the program outside of Visual Studio, you should not notice any problems.
I can reproduce this, but if I check 'Enable Just My Code (Managed Only)' in the Debugging options for Visual Studio, I no longer see the exception.
This works fine for me with no exceptions thrown.
If what you say is true (it only happens when Common Language Runtime Exception notificaion is enabled) then this is an internal exception being thrown and then caught and handled within the .Net framework, and so not something you should be too worried about.
Notice that when the exception occurs the line is highlighted in green (not orange) to indicate that this is simply a notification of an exception occuring rather than the debugger stopping on an unhandled exception.
精彩评论