C# Catch exception or validate parameters beforehand
<p>This is a question about exception handling and prevention.</p>

<pre><code>public static string PathCombineNoEx(string path1, string path2)
{
   if (path1 == null || path2 == null /*Either validate here*/)
   {
      return null;
   }

   try
   {
      return System.IO.Path.Combine(path1, path2);
   }
   catch (ArgumentException /*or catch here*/)
   {
      return null;
   }
}
</code></pre>

<p>Since exceptions are an enormous hit on performance we should try to minimize the chance for exceptions to be thrown. In the following example I've eliminated the chance that <code>Path.Combine</code> could throw an <code>ArgumentnullException</code>. This was very easy to do and does almost not affect performance in any way. However, <code>Path.Combine</code> also throws an <code>ArgumentException</code> if one of the two parameter strings contains any invalid character provided by <code>GetInvalidPathChars</code>. </p>

<ol>
<li>Now, would you recommend to catch this as I did or would you really check for invalid chars before calling the <code>Path.Combine</code>? </li>
<li>What about a general recommendation that can be applied to most situations. </li>
<li>Maybe there is a Microsoft article about that?</li>
</ol>

<p><code>Path.Combine</code> documentation:<br>
<a href="https://msdn.microsoft.com/de-de/library/fyy7a5kt(v=vs.110).aspx" rel="nofollow">https://msdn.microsoft.com/de-de/library/fyy7a5kt(v=vs.110).aspx</a><br></p>

<p>The .NET Reference Source:<br>
<a href="http://referencesource.microsoft.com/#mscorlib/system/io/path.cs,2d7263f86a526264" rel="nofollow">http://referencesource.microsoft.com/#mscorlib/system/io/path.cs,2d7263f86a526264</a></p>

<p>Microsft performance tip (see chapter <em>Throw fewer exceptions</em>):<br>
<a href="https://msdn.microsoft.com/en-us/library/ms973839.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/ms973839.aspx</a></p>