Thursday, April 17, 2008

int.Parse throws FormatException without a reason

For few days I've tried to debug a client's problem - int.Parse kept on throwing FormatException when everything was OK.

Finally I found this post, which says - check the regional settings:
Registry: HKEY_CURRENT_USER\Control Panel\International
Key: sPositiveSign (and the negative one).

My client checked both and they were just fine, but I've decided to write my own int.Parse which does this following:

if (str == "0")
return 0;
return int.Parse(str);

This fixed everything (I did the same for double.Parse too).

No comments: