3 ms·
You don’t always get a stack trace, but it still has to unwind the stack, calling destructors as needed, and check the exception’s type against each catch block
by iainmerrick 7y ago
You don’t always get a stack trace, but it still has to unwind the stack, calling destructors as needed, and check the exception’s type against each catch block.
- earenndil 7y agoHence 'when errors are rare'.
- iainmerrick 7y agoI guess we’re violently agreeing? Exceptions are an order of magnitude (or several orders) slower than function calls and returns; but that can still be efficient overall, if only a tiny fraction of calls fail. I’d simply add that most people greatly underestimate how expensive exceptions are, even in C++.
- AstralStorm 7y agoCalling the destructors is identical to ending any scope in C++, including function calls. Where is that extra expense?
- iainmerrick 7y agoYou likely have to parse exception blocks and maybe chase pointers to find the objects to destroy. In the happy path, you can just call the destructors directly.