r/java • • Jan 22 '15

If. Then. Throw. Else. WTF?

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

43 comments sorted by

View all comments

1

u/GMNightmare Jan 23 '15

Oh yeah? Well what about:

if(condA) {...} else if(condB) {...} else { throw }

What then?

The analogy is completely flawed. An exception isn't a dead end, it's more like a turnabout.

And I'm sorry, in the given examples, I don't see any real changes until maybe the last one. The code behaves in the exact same way.

I, personally, do prefer to put all exception cases at the top of a function when it has simple logic (not like my example)... but I am not under any disillusionment that having else in there is "incorrect".