error when no error

2 posts, 0 answers
  1. Keith Stephens
    Keith Stephens avatar
    83 posts
    Member since:
    May 2010

    Posted 23 Sep 2010 Link to this post

    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.
  2. Svetlozar
    Admin
    Svetlozar avatar
    269 posts

    Posted 01 Oct 2010 Link to this post

    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
  3. DevCraft banner
Back to Top