title: What is a better way to handle exceptions than the following?
body: <p>At first, I was going to do something like the following:</p>
  
  <pre><code>public void WriteToFile(string filePath, string contents)
  {
      try
      {
          File.WriteAllText(filePath, contents)
      }
      catch(Exception ex)
      {
          //Log error
      }
  }
  </code></pre>
  
  <p>But then I decided to catch all the specific exceptions for the method WriteAllText, like the following:</p>
  
  <pre><code>public void WriteToFile(string filePath, string contents)
  {
      try
      {
          File.WriteAllText(filePath, contents);
      }
      catch (IOException ex)
      {
          //An I/O error occured when opening the file
      }
      catch (ArgumentException ex)
      {
         //The exception that is thrown when one of the arguments provided to a method   
           that is not valid.
      }
      catch (UnauthorizedAccessException ex)
      {
         //Unauthorized access
      }
      catch (SecurityException ex)
      {
          //Security exception
      }
      catch (NotSupportedException ex)
      {
          //Invoked method not supported
      } 
  }
  </code></pre>
  
  <p>The above is very verbose and with other methods, it could be more.  Is there a better way to do this so I don't have to write so many catch statements.  Also, if an exception is caught, is it best to return from it, log it. I always get confused on how to handle it.</p>
  
  <p>I have noticed some confusion.  I am going to handle the exceptions, I left out handling the exception to keep this short.  I am going to make use of the ex variable.  The question is more about doing just catch(Exception ex) or multiple catch statements.</p>
  
  <p>I also bring this up because I always here that it is better to handle specific exceptions rather than a catch-all.  If I have misunderstood this, please clarify on what it means.</p>