4 ms·
ok Im stumped :) Would be interested to read some clarification on this. the try always throws an exception, and if i<3 resumes the code. But on the last itera
by achenatx 7y ago
ok Im stumped :) Would be interested to read some clarification on this.
the try always throws an exception, and if i<3 resumes the code. But on the last iteration through it breaks so will not execute code after the exception is thrown. The first 3 times it will execute code after the exception is thrown. Does continue return to the beginning of the for loop or resume execution where the exception was thrown?
If continue returns to the beginning of the for loop then I could see that the code is pointless. But if continue resumes execution inside of dosomething the line after the exception was thrown, then it could actually be useful.
Is your issue that the code does actually work, but conceptually it is horrendous to implement the branching in that way, or is it that the code doesnt work at all, or is that it actually does nothing?
When I see things like this I integrate them into our interview process.
- pault 7y agoSorry, I think there's a couple of confusing things there. I mentioned a try block that always throws, but that was a different bit of code. In the example I posted of the for-loop the try/catch is unrelated to the previous, so we can assume it doesn't throw every time. The only WTF is why are we counting `i` and using `continue` and `break` to control a for loop.
- deleted 7y ago[deleted]
- Scarblac 7y agoThe part in the except: does exactly what the for loop already does, it's completely superfluous. It also has nothing to do with handling the thrown exception.
- janee 7y agoYeah it's pretty weird. Was trying to think of something that would need this exact behavior, assuming it's legit...maybe parsing some piece of text where you expect a fourth part only if the third was parsed successfully and you don't care about the outcome of the previous two ¯\_(ツ)_/¯ Scenarios like this scare the bejubus outta me, it's like a business logic landmine waiting for a refactor tractor to drive over
- janee 7y agoNoooope, looking at it again it does nothing..guessing some off by one error with whatever this thing was intended to do by the author