title: Java Mock throw an exception, then return a value?
body: <p>I am using JUnit 4 and Mockito 2. I am trying to mock a situation where the mocked function returns an exception the first time it is called, and on the subsequent call a valid value is returned. I tried simply having a <code>thenThrow()</code> followed by a <code>thenReturn()</code>, but that is not the correct method apparently</p>
  
  <pre><code>when(stmt.executeUpdate()).thenThrow(new SQLException("I have failed."));
  when(stmt.executeUpdate()).thenReturn(1);
  sut.updateValue("1");
  verify(dbc).rollback();
  sut.updateValue("2");
  verify(dbc).commit();
  </code></pre>
  
  <p>Both calls, however, result in a call to rollback(), which is in the catch statement.</p>