title: How to assert that an exception was thrown regardless of message?
body: <p>I am expecting that if <strong>serial</strong> cannot be parsed with <code>int.TryParse</code>, then it will throw an ArgumentException:</p>
  
  <pre><code>        if(!int.TryParse(serial,out intSerialNumber))
          {
              throw new ArgumentException("The serial number is not numeric.",nameof(serial));
          }
  </code></pre>
  
  <p>However, when I test this behavior my test fails:</p>
  
  <pre><code>    [Test]
      [ExpectedException(typeof(ArgumentException))]
      public void throws_argumentException_if_serial_number_is_not_numeric()
      {
          var sut=new mDevice(serial:"something not numeric",patientid:123);
      }
  </code></pre>
  
  <p>The exception I am getting is:</p>
  
  <p><a href="https://i.stack.imgur.com/FvM8p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FvM8p.png" alt="enter image description here"></a></p>
  
  <p><strong>The expected exception is indeed being triggered, why does the test not pass?</strong></p>
  
  <p>The code for the class:</p>
  
  <pre><code>public class mDevice
  {
      public mDevice(string serial,int patientid)
      {
          int intSerialNumber;
          serial=serial.Trim();
          if(!int.TryParse(serial,out intSerialNumber))
          {
              throw new ArgumentException("The serial number is not numeric.",nameof(serial));
          }
          if(patientid&lt;2)
          {
              throw new ArgumentException("The patient id must be greater than 1.",nameof(patientid));
          }
          Serial=serial;
          PatientId=patientid;
      }//more stuff after this constructor, but not including it here
  }
  </code></pre>