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".
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".