title: How can I write a unit test assertion that checks for an error with specified identifier and with a specific message?
body: <p>I'm using the new <a href="http://www.mathworks.com/help/matlab/matlab-unit-test-framework.html" rel="nofollow">unit testing framework</a> for MATLAB that was introduced in R2013a, matlab.unittest. I would like to write an assertion that both of the following things happen:</p>
  
  <ol>
  <li>An exception with a specified identifier is raised.</li>
  <li>The message of that exception satisfies some condition.</li>
  </ol>
  
  <p>I've found the <a href="http://www.mathworks.com/help/matlab/ref/matlab.unittest.qualifications.verifiable.verifyerror.html" rel="nofollow"><code>verifyError</code></a> method but that only appears to allow me to check the identifier, or the error metaclass. </p>
  
  <p>The other option appears to be <a href="http://www.mathworks.com/help/matlab/ref/matlab.unittest.qualifications.verifiable.verifythat.html" rel="nofollow"><code>verifyThat</code></a> with the <a href="http://www.mathworks.com/help/matlab/ref/matlab.unittest.constraints.html#zmw57dd0e132330" rel="nofollow"><code>Throws</code></a> constraint. That seems more promising but the documentation of <code>Throws</code> appears somewhat sparse and I cannot work out how to make it do what I want.</p>
  
  <p>I realise that I could add the message text to the error identifier but I don't really want to do that. The message text comes from a native library that is called using a mex file. And the text is formatted with spaces and so on. The text could be quite long and would make a mess of the error identifier.</p>
  
  <p>So, is it possible to achieve what I want, and if so how?</p>