When do I have to write the throwable Exception in the Method Definition?
For example my constructor works with both:
public Test(int s, String t) {
if (s <= 0 || t == null) {
throw new IllegalArgumentException();
}
this.s = s;
this.t = t;
}
or:
public Test(int s, String t) throws IllegalArgumentException {
if (s <= 0 || t == null) {
throw new IllegalArgumentException();
}
this.s = s;
this.t = t;
}
And this method works without it as well:
public int mult(int n) {
if (n < 0) {
throw new IllegalArgumentException();
}
return n * this.s;
}