3 ms·
That might be the correct way to write that code if the situation is not recoverable. Say you have public int doubleFooBarBazQux(Foo foo) { return f
by guelo 17y ago
That might be the correct way to write that code if the situation is not recoverable.
Say you have
public int doubleFooBarBazQux(Foo foo) {
return foo.bar().baz().qux() * 2;
}
That might throw a NPE, but what's the alternative?
- jrockway 17y agoI typed this into Eclipse, and it's super-awesome-excellent auto-code-writer decided that it should be: public int doubleFooBarBazQux(Foo foo) throws NullPointerException { try { return foo.bar().baz().qux() * 2; } catch(NullPointerException e){ throw new NullPointerException(e.getMessage()); } } If only there was a right-click option for "improve quality"...
- ewjordan 17y agoYeah, the generated code is asinine, but what would you prefer? "Improve quality" in this case would just leave out the try/catch altogether. Is there another behavior that would be better, given that we know nothing about foo, bar, baz, or qux?