4 ms·
You don't have to start over with the whole language. Just use -fno-exceptions in your project and dictate the use of std::optional, or absl::StatusOr, or whate
by jeffbee 5y ago
You don't have to start over with the whole language. Just use -fno-exceptions in your project and dictate the use of std::optional, or absl::StatusOr, or whatever your favorite variant return type may be. For the examples in the article, it may be perfectly fine to not support failure, to simply std::abort whenever the sqrt of a non-positive is requested and rename the function sqrt_or_die.
- jmyeet 5y agoExcept if that's incompatible with libraries you're using. For the record, I like absl::StatusOr<>.
- kevin_thibedeau 5y agoYou also have to abandon operator new and STL unless you want to pretend they never fail.
- pjmlp 5y agoJust use the no_throw variant, no need to abandon new.
- jeffbee 5y agoRight, I use an allocator that just aborts. Imagining your program can recover from alloc failures has always struck me as fanciful, or at least out of the realm of my experience.
- Inityx 5y agoIt's a legitimate thing in embedded and other memory-constrained circumstances, when you have something like a large cache and an allocation failure can trigger manual pruning or GC.