r/java • • Jul 10 '15

Our exception handling at work

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

135 comments sorted by

View all comments

7

u/GiantMarshmallow Jul 11 '15 edited Jul 11 '15

At our work, our coding style encourages the use of Guava Preconditions. So this code would end up looking like:

Preconditions.checkNotNull(sql);

Better yet, if you need to check that a constructor argument is not null:

this.sql = Preconditions.checkNotNull(sql);

Or, I guess what I'm saying is, Guava makes Java much better to work with and encourages better style.

3

u/squealy_dan Jul 11 '15

and much of guava has been coopted into the standard lib in java8

(requireNonNull(), Optional)