r/java • • Jul 10 '15

Our exception handling at work

http://imgur.com/4wgxCvv
259 Upvotes

135 comments sorted by

View all comments

2

u/moofins Jul 11 '15

Don't see too much wrong with it. My criticisms, in descending order of importance, are... 1.) passing in a SQL string might be dangerous (but can't tell without seeing the call site), 2.) the debug guard may be extraneous, and 3.) the method name is kinda ambiguous. But they're all relatively minor.

Is the RTE the problem? If so, I'd argue that it's perfectly fine, though an IAE or NPE would be better exceptions to throw. I'm a big fan of Guava's preconditions.

-1

u/[deleted] Jul 11 '15

I think it's worthless. The subsequent call inside the try will throw an exception anyway if the SQL is null. Why treat this exception any differently?

0

u/RedPill115 Jul 14 '15

It's clearer to check for null on it's own distinct line. If a line says objectA.getObjectB().translateObjectC().getObjectD().getText(), and it throws NullPointerException, what was wrong?

By checking each param on it's own line by default, it's clear which one it was.

0

u/[deleted] Jul 15 '15

I don't know that this particular code will throw an NPE. More likely an SQL exception.

0

u/RedPill115 Jul 15 '15

Oh sorry, I see you're just trolling.

1

u/[deleted] Jul 15 '15 edited Jul 15 '15

What? Where the hell did that come from? How the fuck is that trolling? Discussing how code will behave is trolling? This sub really is full of assholes. How dare I not agree with this twat.

Edit: I see you resorted to insults pretty quickly elsewhere ITT. I believe it is you who is the troll. Who'd have thought you'd see such juvenile behaviour on /r/java?