title: Verifying behavior when testing a method that throws an exception
body: <p>Recently, in a code review, a colleague said "Tests should not have try-catch blocks".  He also pointed me to information about <a href="http://junit.org/apidocs/org/junit/rules/ExpectedException.html" rel="nofollow"><code>ExpectedException</code></a>, and I was able to use it to rewrite some of my tests that were performing checks on the exception data.</p>
  
  <p>However, I'm encountering a situation where I'm not sure I can eliminate the try-catch.  I'm writing a unit test for a method that will throw an exception <strong>and</strong> that will perform some behavior that I need to verify using JMockit.  Suppose the code under test contains something like</p>
  
  <pre><code>try {
      ...code...
  } catch (SomeException e) {
      statusMessage.send("Failure", &lt;parameters with some data&gt;);
      throw e;
  }
  </code></pre>
  
  <p>The JUnit test currently looks like</p>
  
  <pre><code>@Test
  public void test() {
      ... set things up ...
      try {
          callTheMethod();
          fail("No exception thrown");
      } catch (Exception e) {
          assertEquals(SomeException.class, e.getClass());
      }
      new Verifications() { {
          statusMessage.send("Failure", &lt;expected data&gt;);
      } }
  }
  </code></pre>
  
  <p>I can't find a good way to get rid of the try-catch.  I don't see a problem with having it there, personally, but if I don't at least <em>try</em> to get rid of it I'm likely to <em>catch</em> heck from my colleague :) :) :) </p>
  
  <p>The <code>fail</code> and <code>assertEquals</code> aren't necessary.  If there's a simple way to tell JUnit/JMockit to simply ignore any exception from <code>callTheMethod()</code> and continue, that would be fine--I can create another test to check the exception.</p>
  
  <p>Is there some JUnit or JMockit feature that would let me accomplish what I'm trying to do?</p>
  
  <p>[Note: Edited to make it clear that the behavior I'm testing is a call on a mocked object, not a static method call.  It really isn't relevant to the question.]</p>