Is it a good practice to use exception for managing cases that are not errors ?
Like in JavaScript and Python that manage the StopIteration case in generators (yield keyword).
I would say No, spontaneously. Exceptions should be used for exceptional states, not for regular program flow.
Not usually, no. ASP.NET uses this for Response.Redirect
- actually aborting the thread, then catching the exception and resetting it. It's very nasty, but it does let you basically "quit" the request without every level of the stack being aware that it needs to return immediately.
Try to avoid wherever possible. If you think you absolutely have to do it, consult two colleagues, present the design and ask if they can do it more cleanly somehow. If none of you can think of a better way round it, do it with extensive documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With