I have this method:
public String getNum(int x) throws Exception { if(x == 0) { throws new Exception("x cannot be 0"); } ... } now in my JUnit test, I try this
@Test(expected=Exception.class) public void testNum() { String x = getNum(0); } But Eclipse still wants to me to either add a throws declaration or surround with try catch for String x = getNum(0);. What did I do wrong? This test should pass since I expected an Exception when I pass in 0.