|
|
|
|
|
by forrestthewoods
3 days ago
|
|
> You really don't. Like I said, it's kind of the whole point of exceptions. No, this is actually just wrong. With exceptions you “don’t have to think about” the exception getting caught by some higher level catch. But you do have to think about it in the sense that every single line in your code could unwind. Which makes ensuring you remain in a valid state more difficult. One of the issues with exceptions isn’t the throw. It’s what do you do after you catch. > That a tool can be misused doesn't delegitimize the tool. I’m always open to the possibility that if something I’ve seen has been bad 100 times then on the 101st it might be good. But at some point you really just have to call a spade a spade. |
|
No, this is actually just wrong. There is code that can throw, and there is code that cannot possibly throw. The way you write exception-safe code is by not holding manually-managed resources (e.g. raw pointers that own heap allocations, or file descriptors that must be close()d, or anything else that needs cleanup code that has not been put in a destructor) during sections that may throw. In other words, use RAII to manage your resources, regardless of whether exceptions may be thrown.