3 ms·
That's basically how exceptions work in a modern C++ ABI. And it's why taking an exception is so slow--throw has to lookup the caller in a huge map to find the
by wahern 6y ago
That's basically how exceptions work in a modern C++ ABI. And it's why taking an exception is so slow--throw has to lookup the caller in a huge map to find the address of the caller's catch handler to jump to, then that function has to do the same, etc, all the way up the stack.
In principal exceptions should be much faster than explicit error checking, and as in the article this is often the case. But modern CPUs are really good at speculating through conditional branches. To achieve "zero cost" exceptions compilers often have to do non-trivial code reordering and duplication to segregate the non-exception and exception branches. Sometimes this necessary rewriting can have a negative impact on performance.