The program flow should be as direct as possible (since even then applications become quite complex) and use standard control flow structures. The next developer, who might touch the code, may not be you and (correctly) misunderstand the non-standard way of using exceptions instead of conditional expressions to define the control flow.
I am struggling with a slightly different bias from this problem right now while refactoring old code.
The biggest problem I find with this approach is that using try / catch interrupts the normal program flow.
In the application I'm working on (and this is different from the sample that you used), exceptions are used to communicate from a method call that gives the given result (for example, it searches for the account number and does not find it) happened. This creates client-side spaghetti code because the calling method (during a non-exceptional event or case of a normal use case) breaks out of any code that it executed before the call and into the catch block. This is repeated in some very long methods many times, which makes the code very easy to read incorrectly.
In my situation, the method should return a value for each signature for all but truly exceptional events. The exception handling mechanism is designed to take a different path when an exception occurs (try and restore it inside the method so that you can return normally).
In my opinion, you could do this if you very much endowed your try / catch blocks; but I think this is a bad habit and can lead to code that is very easy to misinterpret, as the calling code interprets any abandoned exception as a message like "GOTO" , changing the program flow. I am afraid that although this case does not fall into this trap, it can often lead to a coding habit leading to the nightmare that I live now.
And I do not like this nightmare.
Scott Taylor Feb 19 '10 at 18:14 2010-02-19 18:14
source share