I am very confused. Some of these ramblings are just plain wrong, like > But exceptions come at a performance cost. No they don't. An exception that isn't thrown costs nothing. Also > Let’s say I want to know if a constructor failed. I have two options, one is to pass in an in-out parameter, the other is to the throw an exception. Using a factory function instead is a third option that avoids this. Besides, this is a…
Wait whaaat?
When every expression can throw anything, the compiler and the user both loose the ability to reason about code locally. They change any function from returning one value of one type, to returning any value of any type.
This:
- has a performance cost: it breaks lots of compiler optimizations that require knowing where and what can functions return.
- has a compile-time cost: compiler needs to generate code for landing pads all over the place, this code must be optimized, etc.
- has a code-size cost: the landing pads must be generated in the binary,
- has a usability cost: users can't reason about their programs if they can't reason about where functions can return and what they can return
- has a teachability cost: users have to be taught _a lot_ about how to use exceptions properly because of their cost. Herb Sutter has a whole damn series of books, a series of damn books, about how to use exceptions properly and avoid their pitfalls. When you need a series of books to explain 1 single feature of your programming language, that feature is _wrong_. And writing and reading these books has a huge cost.
Exceptions are as free as Google or Facebook. You can use them for free as long as you gift them your soul so that they can sell it for profit.