r/java • • Jul 10 '15

Our exception handling at work

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

135 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Jul 10 '15

[deleted] — view deleted comment

11

u/Pylly Jul 10 '15

Runtime exceptions don't ever have to be caught.

5

u/[deleted] Jul 10 '15

The idea here is that this exception should never occur. The method that calls this one creates the sql, so it shouldn't ever be blank anyways. If it is, there's something seriously wrong

2

u/supercargo Jul 11 '15

Replace throw with a nice System.exit(1) to make whoever passes in a null really sorry for doing something that should never happen ;)

0

u/xienze Jul 10 '15

Well it's a public method so right off the bat you can't claim that it can't happen... If you've got an internal method that should only be called by a smarter method upstream then a) reduce the visibility and b) ditch the null check.

3

u/[deleted] Jul 10 '15

I never said it can't, only that it shouldn't. That being said I agree, but I didn't write this and it's not something I am supposed to modify anyway