title: How to check if a function throws an exception in c#?
body: <p>How to check if a function throws an exception in c#?</p>
  
  <pre><code>public List&lt;string&gt; GetFileNames()
  {
      try
      {
          // do something
          // return something
      }
      catch(Exception ex)
      {
          // do something
          // log something
      }
  }
  </code></pre>
  
  <p>then i will call <code>GetFileNames()</code> somewhere in my code, but I want to check if it throws an exception,
  like,</p>
  
  <pre><code>var list = GetFileNames(); // can be 0 count
  
  if(GetFileNames() throws an error)
  {
      DoThisMethod()
  }
  else
  {
      DoThisOtherMethod();
  }
  </code></pre>