title: Is it possible to add an error code to an exception?
body: <p>To throw an exception, by the moment I am using this way?</p>
  
  <pre><code>throw new ArgumentException("My message");
  </code></pre>
  
  <p>But if a mtethod can throw an ArgumentException for many reasons, I would like to know the exact reason of the exception.</p>
  
  <p>I know that I could use this away:</p>
  
  <pre><code>throw new ArgumentException("MyParamName", "MyMessage");
  </code></pre>
  
  <p>But this cases doesn't help so much if the same parameter can have many reasons to throw the ArgumentException. For example, I have a parameter in a method with two properties and one needs to be greater than 0 and the other one less than 0. I would like to send an error code, 001 when the first parameter is not greater than 0 and 002 when the second parameter is not less than 0. In this way. But I don't know if it is possible set an error code in the exception.</p>
  
  <p>I could use this way:</p>
  
  <pre><code>throw new ArgumentException("My message " + "(001)");
  </code></pre>
  
  <p>At the end of the message I could add the error code, but I had to search for the substring (001). But I am wondering if there would be a better  option.</p>
  
  <p>Another way it could be create my own exception, but if I have an ArgumentException, I think that create a new exception only to have a property for the error code and include the original exception it is little overhead.</p>
  
  <p>So my question is, what is the best option? There are another solutions?</p>
  
  <p>Thanks.</p>