3 ms·
Without exceptions you can't do RAII (because you can't do nontrivial work in constructors, because you have no way to report failure) which is probably C++'s o
by lmm 10y ago
Without exceptions you can't do RAII (because you can't do nontrivial work in constructors, because you have no way to report failure) which is probably C++'s one real selling point. (There are other reasons I'd say it isn't a fine language - mainly the lack of sum types and the way templates are only checked after full expansion (that one will at least be fixed if and when concepts make it into the language)).
- nathell 10y agoRAII used to be incompatible with exceptions (I'm not sure whether anything changed for the better in C++17). The reason is that you can't throw exceptions from destructors, and e.g., on Linux, destruction of the file object (wrapping a file descriptor) can result in an error because close() may well return -1 setting errno to EIO. See `man 2 close` for details.
- tcbawo 10y agoThat's really not true. It takes a little discipline to ensure your constructor will succeed prior to calling it, but it's worth it. You generally want to make your destructor noexcept, so you get free implicit move optimizations.