Re: throwing exception from constructor




Andrew McDonagh wrote:

[snip]
> primitives (int long, boolean, etc) can not be assigned the NULL value -
> hence the error you get. ...

Thank you Andrew.

Are the assignments of arg1 & arg2 to null unnecessary here?

public class TestClass {

public TestClass(long arg1, long arg2)
throws IllegalArgumentException {
if (arg1 > 0xffffffffL || arg1 < 0 || arg2 > 0xffffffffL || arg2 <
0) {
this.arg1 = null;
this.arg2 = null;
throw new IllegalArgumentException();
}
else {
this.arg1 = arg1;
this.arg2 = arg2;
}
}
public Long getArg1() {
return arg1;
}
public Long getArg2() {
return arg2;
}
private final Long arg1;
private final Long arg2;
}


.