SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Carey Brown wrote:Exceptions should not (in general) be used for flow control.
Claude Moore wrote:
Carey Brown wrote:Exceptions should not (in general) be used for flow control.
That's interesting. What do you mean for flow control ? I've wrote at least a dozen of REST API, all of them following this pattern:
- check phase : check if parameter passed are valid, if not throw a proper exception;
- business logic execution: execute business logic and throw exception only if an unrecoverable error is met.
For example, one of such APIs executes reservations of goods in a warehouse to a given customer order. During the check phase, my API throw an exception, for example, if an already fullfilled order is passed as parameter.
To be honest, I don't think - but I could be wrong, of course !! - that doing so were a bad practice. Instead, localizing all formal controls (i.e like the check if given order is valid or not) at the very beginning of my API led me to write more clear code.
What am I missing ?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Christian Wansart wrote:@Carey Brown: so you use integers instead of exceptions to create handle different situations?
Consider Paul's rocket mass heater. |