title: Is it bad practice to use an exception message property to check for particular error?
body: <p>Sometimes the exception type is unique enough to indicate the exact issue, such as an <i>ArgumentOutOfRangeException</i>. Othertimes, the exception is more general and could be thrown for several reasons. In this scenario, it seems the only additional information is found in the exception message property.</p>
  
  <p>In my current circumstance, I am getting a CommunicationException which throws the error message:</p>
  
  <p><strong>The maximum message size quota for incoming messages (65536) has been exceeded</strong></p>
  
  <p>As multiple different errors may be thrown via the CommunicationException, is it bad practice to use the message property to determine the cause, like so:</p>
  
  <pre><code>catch (CommunicationException ex)
  {
      if (Regex.IsMatch(ex.Message, "The maximum message size quota for incoming messages .* has been exceeded"))
      {
          // handle thrown exception
      }
      throw;
  }
  </code></pre>
  
  <p>Will these messages be constant and reliable on all systems? Are there any other considerations, such as localization?</p>
  
  <p><strong>Conclusion:</strong></p>
  
  <p>My scenario with the 'CommunicationException' was a bad example, as I later realized that there was a QuotaExceededException in the InnerException property. Thanks to the responses, I knew to look for any data that existed in the exception to indicate the exact cause. In this case, it was the InnerException property.</p>
  
  <p>In terms of the question regarding whether or not the message property should be used to determine the cause, it seems to be the general consensus that it should be avoided unless there is no alternative. The message property value may not remain constant over varying systems due to localization.</p>