I’ve recently read in BS’s c++ book, that it is ok to throw the result of a recursive search to immediately return from the whole call stack at once.
Is it ok to do the same in java? I know it is possible, but is it discouraged and considered a to have a bad smell?
It is easier than using a ‘found’ flag and checking it every time.
I’ve recently read in BS’s c++ book, that it is ok to throw the
Share
I definitely would go for a flag. Sure you can do it with
Exceptionbut it is not meant to control code flux with exceptions. Exceptions are not free in cost, while a simple check of the flag would cost O(1).