JUnit test exception handling fail 2

Posted by Jens Jäger on May 09, 2011

I just found this peace of code in a big java project i’m working on:

Wtf? I changed it to:


Use this link to trackback from your own site.


Leave a response

  1. Stefan Wed, 24 Aug 2011 18:49:44 CEST

    The stacktrace gets lost with your modification. Imho, the best alternative would be to not catch the exception at all and change the throws clause of the method accordingly.

  2. Jens Wed, 07 Sep 2011 21:16:16 CEST

    Hey Stefan,
    thanks for your reply. You are right. I have to say that in this case the stack trace was not very use full.

    Anyway with JUnit4 the @Text(expected = MyException.class) annotation makes live much easier.



Information about Data protection