Thursday, April 05, 2007

FormatException thrown by Convert.ChangeType Method

According to Microsoft's online documentation the method Convert.ChangeType(Object, Type) can throw the following two exceptions:
  • InvalidCastException
  • ArgumentNullException

Unfortunately, this list is not complete. When you try to convert the string "oops" to int32, this method throws a System.FormatException with the message "Input string was not in a correct format."

In this regard the online documentation for .NET 2.0 is incorrect. The behavior might be the same for .NET 3.0. I didn't verify the latter.

1 comments:

king said...

The behavior is the same for .NET 3.5.0.0.!

Post a Comment

All comments, questions and other feedback is much appreciated. Thank you!