title: Throwing an Exception in an if-else block
body: <p>To start, I realized there is probably a better way to do this, and rather than throwing an exception I should just handle the condition better.  That being said, I ran into some unexpected behavior and I'm more curious why this is happening than using it my application.</p>
  
  <p>In a method, I am attempting to access a file provided by the user.  At he beginning of the method, I am checking to make sure that the path to the file is not <code>Null</code> or <code>String.Empty</code> and throwing an exception if it is.  When I was testing, I am finding that the exception is thrown regardless of the condition.  Is this normal behavior, or am i missing something?</p>
  
  <pre><code>public static XElement Foo(String path)
  {
      if (String.IsNullOrEmpty(path))
      {
         throw new ArgumentNullException(); // this exception is thrown  
                                            // regardless of the value of 'path'
      }
  
  
      // code to open and parse file
      // returns XElement
  }
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>In my testing scenerio, the calling method is just sending a default path that i hard coded for the test.  I have not completed the UI, so the code for the user to define the path is not complete.</p>
  
  <pre><code>private const string c_fooPath = "C:\\test\\text.txt"
  
  public void CallingFoo()
  {
      var xml = Foo(c_fooPath)
  
      // some code
  
  }
  </code></pre>
  
  <p>UPDATE #2:</p>
  
  <p>Just to mention some of my other tests i have tried.  I have tried </p>
  
  <pre><code>if (String.IsNullOrEmpty(path))
  {
      Console.WriteLine("testing")       // this line is skipped when my condition is
                                         // false but runs when  i force it to be true
  
      throw new ArgumentNullException(); // this exception is thrown  
                                         // regardless of the value of 'path'
  }
  
  if (false)
  {
      throw new ArgumentNullException(); // the exception is not thrown here - the only
                                         // condition i have found so far.
  }
  
  public static XElement Foo(String path)
  {
      path = "test";
  
      if (String.IsNullOrEmpty(path))
      {
         throw new ArgumentNullException(); // exception is still thrown  
      }
  
  
      // code to open and parse file
      // returns XElement
  }
  </code></pre>