Exception vs Errors | Chris Lattner and Lex Fridman
C++
- In c++ they call it the zero cost exception handling but it’s not really zero cost
- looking up and searching tables will cost you and can cost alot compare to returning a value
Other newer languages like Swift, Go, Rust
- under the hood does something similar to returning a value
- return a good value or error value
- will cost the same as returning from a function
How does it work?
- if a function throws error and the function call was in a try block it will jump to except block.
Conclusion
- throwing exception in c++ can be costly and have to be considered carefully