3 ms·
Stack unrolling is a complicated process. It's tempting to think of them as a kind of return value, but most languages do not represent them this way. (I belie
by marcosdumay 5y ago
Stack unrolling is a complicated process.
It's tempting to think of them as a kind of return value, but most languages do not represent them this way. (I believe it's a performance optimization.)
Flying to the nearest catch can also be complicated, as it's a block, that involves variable creation, and this possible stack changes. Again it's easier to model as a normal block break and then a jump, but that's not the usual implementation.
- loa_in_ 5y agoI always expect them to use (thread-) global state, not unlike good old errno just more structured. There's always at most one bubbling up so that's how I would do it.
- marcosdumay 5y agoBut then you'll have a branch on every failable operation and slow down the happy path. This is not too different from passing the error as a value. Instead, compilers use long jumps and manually edit the stack. I'm not sure it makes a lot of difference today, but branches were really problematic by the time the OOP languages were popularizing.
- astrange 5y agoThey're not bad these days if they're predictable. There's a code size cost, but there's also a cost to emitting all the cleanups and exception safety too. For instance Swift doesn't have exceptions - it has try/catch but they simply return, though with a special ABI for error passing.
- wruza 5y agoI believe that today a cold branch is just gets predicted as not taken and stays as such because it never jumps (in terms of a predictor’s statistics, not literally).