I have the following code block and I wonder why a run time error is thrown rather than me being able to handle the exception within catch
(I put a breakpoint at int i = 1;
but it is never reached):
var stringArray = textRow.Split(Delimiter);
try
{
var a = DateTime.Parse(stringArray[0]);
var b = double.Parse(stringArray[2]);
var c = double.Parse(stringArray[3]);
}
catch (Exception e)
{
int i = 1;
}
The following FormatException
Occurred error is thrown:
System.FormatException occurred
_HResult=-2146233033
_message=The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.
HResult=-2146233033
IsTransient=false
Message=The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.
Source=mscorlib
StackTrace:
at System.DateTime.Parse(String s)
InnerException:
I understand that I can use TryParse
but I like to test whether try/catch will make for better performance because I iterate over this code block many millions of times.
Thanks