On 21.04.2004 15:34, Ugo Cei wrote:

Marc Portier wrote:

yeah, but this is something that never needs to be catched it really is a programming error, so I find the test for null unesessary and the possible resulting NPE as more then RTE enough to commincate the coding error.


The problem with the NPE is that you'd need to look at the stacktrace to find what the exception is about, as you get no meaningful message, and the exception might be thrown when you try to dereference the null pointer, which could be far from where getId() is called. What I propose is to throw a RTE when the widget is built. Fail early, if you can.

Admittedly, this is just a convenience for the developer.

NPE is really bad - not only here - for the two mentioned reasons. But if you insist on your NPE you can change Ugo's proposal to


if (id == null) {
  throw new NPE("id must not be null");
}

So we have NPE, which is RuntimeE, meaningful message and early failure :)

Joerg

Reply via email to