4 ms·
What's exception handling actually doing internally? Genuinely interested and i need to know. Must be some kind of "goto catch block" internally when you thro
by dana321 7y ago
What's exception handling actually doing internally?
Genuinely interested and i need to know.
Must be some kind of "goto catch block" internally when you throw an error. It has to stop the execution and jump somewhere, but that somewhere is set in the code where it catches the error.
If you're calling a function then that function throws an error, it has to prematurely exit to somewhere so there must be a stack of the locations of the catch blocks or something? That then unroll as you exit the try/catch blocks as well.
- gnulinux 7y agoFor gcc/clang C++, internally, it will unwind the stack until it finds a handler. This way it doesn't have to do anything at the moment of setting a handler (i.e. "try" in the underlying code), as a trade-off it's relatively expensive to throw an exception. But note that C++ standard does not specify this, so it's fair game for compiler to do anything. E.g. it can use long jumps, or just dispatch different functions based on all possible exception states (which produces very large binaries).
- dana321 7y agoThanks for that, nice to know!