title: Unexpected exceptions in Java Unit tests
body: <p>I'm really a newbie to JUnit and unit testing in general and I'm struggling to find the right approach. What is the better way to deal with unexpected exceptions, and why?</p>
  
  <p>Method A:</p>
  
  <ol>
  <li>first catch the expected ones, fail the test with a message</li>
  <li>in the last catch block, catch a general Exception and fail the test with some "Unexpected exception has occured" message</li>
  </ol>
  
  <p>Method B:</p>
  
  <ol>
  <li>catch only the expected ones, fail with a message</li>
  <li>mark the test method with <code>throws Exception</code> and let anything unexpected "bubble up" completely out of the test</li>
  </ol>
  
  <p>And to add to the confusion, by saying "unexpected exception", I mean either one of these things:</p>
  
  <ol>
  <li>an exception that the method being tested claims to throw, but on in this case. For example, my method throws IllegalArgumentException and NullPointerException, but in this try block, I expect it to throw IllegalArgument; NullPointer is considered unexpected. Catch and fail or bubble up?</li>
  <li>a general Exception I really cannot anticipate</li>
  </ol>
  
  <p>I'm aware this question comes out a bit confusing, I'm getting lost in it myself, but hopefully someone will give me any kind of hint. Won't blame you for downvotes, it's still worth the risk :)</p>