Exception handling in most languages ββis usually slow. Most compilers, interpreters, and virtual machines (which support exception handling) consider exceptions (language idiom) as exceptions (unusual). Performance optimization involves trade-offs and the quick implementation of exceptions will usually mean that other areas of the language will suffer (either in performance or in the simplicity of the design).
On a more technical level, exceptions usually mean that the VM / interpreter (or the execution runtime library) needs to save a bunch of state and start pulling all the state in the function call stack (called unwinding) until the point where a valid catch (except) is found.
Or, looking at it from a different point of view, the program stops working when an exception occurs and the "debugger" takes over. This debugger searches back through the stack (call function data) for a catch that matches the exception. If he finds one, he will clear things and return control to the program at that moment. If he does not find it, he returns control to the user (possibly in the form of an interactive debugger or REPL).
kanaka Oct 14 2018-10-10T00: 00Z
source share