In this example:
try
{
this.myEnum = (MyEnum)Enum.Parse(typeof(MyEnum), queryStringKeyValue);
}
catch (Exception)
{
this.myEnum = null;
}
How to avoid the introduced dependency on catching a generic exception? I’m getting no clues from ReSharper. Ideally, I’d like to get rid of the try / catch.
As others have stated, the TryParse methods return a boolean on failure instead of throwing an exception. But also, look at http://msdn.microsoft.com/en-us/library/essfb559.aspx. It lists the Exceptions that may be thrown, so rather than catching the generic Exception, you could catch the specific exceptions being thrown like ArgumentException. The example on that page shows catching ArgumentException.