This is a migrated thread and some comments may be shown as answers.

error when no error

1 Answer 30 Views
Quick Fixes
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Keith Stephens
Top achievements
Rank 1
Keith Stephens asked on 23 Sep 2010, 11:05 PM
I have this code, and I am getting false errors.

DateTime? dummyDate = null;
              try
              {
                  dummyDate = DateTime.Parse(anyString);
                  // dummyDate = DateTime.Parse(anyString, System.Globalization.CultureInfo.CurrentCulture("en-US").DateTimeFormat);
                  // dummyDate = Convert.ToDateTime(anyString);  //DateTime.Parse(anyString);
              }
              catch
              {
                  return false;
              }
              return true;
JustCode give an error of dummyDate not used.  It is used in my try block.

1 Answer, 1 is accepted

Sort by
0
Svetlozar
Telerik team
answered on 01 Oct 2010, 10:57 AM
Hi Keith Stephens,

Currently, we treat variables as unused until they are read. We will consider once again the options in that scenario (maybe we should treat them as used for read and write access as well).

We have fixed the issues with unused warnings for ref/out variables/parameters in our codebase. The fix will be included in our next internal build.

About the code snippet you posted, the variable is actually unused. You can cause the side effect without the assignment.

try
{
   DateTime.Parse(anyString);
}
catch
{
  return false;
}
return true;


The problem here would be that removing the variable will remove the assignment too. We will fix that by keeping the right expression if it is a method invocation.

Just a note, you can use DateTime.TryParse() method and get rid of this try {} catch {} stuff.

If you have any other problems or suggestions, please don't hesitate to write back.

Best wishes,
Svetlozar Angelov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Quick Fixes
Asked by
Keith Stephens
Top achievements
Rank 1
Answers by
Svetlozar
Telerik team
Share this question
or