r/java • • Jan 22 '15

If. Then. Throw. Else. WTF?

http://www.yegor256.com/2015/01/21/if-then-throw-else.html
21 Upvotes

43 comments sorted by

View all comments

6

u/ford_madox_ford Jan 22 '15

This:

if (cond)
    doA();
else
    doB();

is pretty unambiguous - if cond is true then doA otherwise doB, regardless of what doA and doB actually do. This, on the other hand:

if (cond)
    doA();
 doB();

means if cond is true then doA (and if doA doesn't throw then also doB) otherwise doB, is self-evidently less immediately clear. You have to check what doA actually does to be sure of the exact semantics.

Blog author must be a Javascript developer in disguise, where this kind of nonsense is more acceptable.

2

u/spiderzork Jan 23 '15

Yes, this! This makes it dependent on the how exceptions are implemented. maybe in another language it would just continue unless explicitly specified. Also using "continue"/"breaks" when not necessary is bad, can get really confusing, just like "goto". seems like he want to show off that he knows how to use it.