Feeds:
Posts
Comments

Archive for the ‘Windows Phone 7’ Category

It’s not present in the WP7 version of mscorlib. Eventually I wrote code like this:

ForumType forumType = ForumType.Unknown;

try
{
    string enumLine = forumTypeInput.Substring(. . .);
    forumType = (ForumType)Enum.Parse(
        typeof(ForumType), enumLine.Trim(), true);
}
catch (ArgumentException)
{
}

Note how I only catch (and swallow) ArgumentException. The call can throw an ArgumentNullException too but that would indicate an application code error, so you should not swallow it. Any other unhandled errors also need to be correctly handled so this is the only exception you should swallow. Kinda surprising they decided to drop TryParse though, since it’s not a particularly heavy method.

Read Full Post »

Follow

Get every new post delivered to your Inbox.