Timeline for Is it wrong to prefer exceptions to centralize error handling logic?
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 2, 2018 at 19:55 | vote | accept | void.pointer | ||
| Jun 4, 2018 at 16:57 | comment | added | Robert Harvey | @NicolBolas: So it comes down to language idioms, as I explain in my answer. | |
| Jun 4, 2018 at 16:47 | comment | added | Nicol Bolas | @RobertHarvey: Defined behavior has costs (in this case, a condition+throw). We don't like paying costs needlessly in C++ land. Preconditions are things that an API assumes to be true. Defined behavior is about things that will be verified to be true. | |
| Jun 4, 2018 at 16:07 | comment | added | Robert Harvey | @NicolBolas: Wouldn't defined behavior always be preferred? | |
| Jun 4, 2018 at 15:57 | comment | added | Nicol Bolas | @RobertHarvey: The point of a "precondition" is that if you violate it, you get undefined behavior. Throwing is well-defined behavior; it's a part of the function's interface. That is, there's a difference between a function which can't handle an empty string and a function that throws on getting an empty string. Just as there is a difference between a function that can't handle an empty string and a function that simply doesn't do anything to an empty string. | |
| Jun 4, 2018 at 15:37 | answer | added | Robert Harvey | timeline score: 8 | |
| Jun 4, 2018 at 15:06 | comment | added | Robert Harvey | I'm wondering why you think throwing on a precondition failure constitutes "flow control." If you can't throw there, then where can you throw? | |
| Jun 4, 2018 at 14:51 | review | Close votes | |||
| Jun 9, 2018 at 3:02 | |||||
| Jun 4, 2018 at 14:28 | comment | added | void.pointer | I think the guarantee is mostly open. As far as the language goes, the only strict guarantee you can make is that something will not throw. The alternative is can throw. In addition to that, I can document cases that are guaranteed to throw based on logic/business rules, but that is by no means comprehensive (and usually never is, so I think 99% of the time it's the latter). Sorry if I am misunderstanding your question. | |
| Jun 4, 2018 at 14:25 | history | edited | void.pointer | CC BY-SA 4.0 | added 945 characters in body |
| Jun 4, 2018 at 14:21 | comment | added | Deduplicator | Hm. Does the functions contract guarantee that it will throw under the circumstances, or is it left open? If the former, consider what is more costly, considering development, maintainance and efficiency, and whether that's significant enough to matter. If the latter, well there is nothing to talk about. | |
| Jun 4, 2018 at 14:01 | history | asked | void.pointer | CC BY-SA 4.0 |