| ▲ | tester756 7 hours ago | |||||||||||||||||||||||||||||||||||||
They're good for exceptional situations where foundamental, core assumptions are broken for some reason. In such scenario there's no error recovery, software is expected to shutdown and raise loud error. | ||||||||||||||||||||||||||||||||||||||
| ▲ | jesse__ 7 hours ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||
If you're planning on shutting down, what's the fundamental difference between throwing an exception, vs simply complaining loudly and calling exit() ..? | ||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||
| ▲ | spacechild1 5 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||
> They're good for exceptional situations where foundamental, core assumptions are broken for some reason. No, that's what assertions or contracts are for. Most exceptions are supposed to be handled. The alternative to exceptions in C++ are error codes and `std::expected::. They are used for errors that are expected to happen (even if they may be exceptional). You just shouldn't use exceptions for control flow. (I'm looking at you, Python :) | ||||||||||||||||||||||||||||||||||||||
| ▲ | ljm 6 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||
Yet, if you can only explain an exception using the word ‘exception’ you’re not making any head way. I like the idea of an exception as a way to blow out of the current context in order for something else to catch it and handle in a generic manner. I don’t like the idea of an exception to hide errors or for conditional logic because you have to know what is handling it all. Much easier to handle it there and then, or use a type safe equivalent (like a maybe or either monad) or just blow that shit up as soon as you can’t recover from the unexpected. | ||||||||||||||||||||||||||||||||||||||
| ▲ | dijit 7 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||
I use asserts for this purpose. | ||||||||||||||||||||||||||||||||||||||