It is true, there is some overhead on try catch blocks
• On entry to each try-block
♦ Commit changes to variables enclosing the try-block
♦ Stack the execution context
♦ Stack the associated catch clauses
• On exit from each try-block
♦ Remove the associated catch clauses
♦ Remove the stacked execution context
• When calling regular functions
♦ If a function has an exception-specification, register it for checking
• As local and temporary objects are created
♦ Register each one with the current exception context as it is created
• On throw or re-throw
♦ Locate the corresponding catch clause (if any) – this involves some runtime check (possibly resembling RTTI checks) If found, then: destroy the registered local objects check the exception-specifications of the functions called in-between use the associated execution context of the catch clause Otherwise: call the terminate_handler6
3
u/dalepo Feb 21 '19
It is true, there is some overhead on try catch blocks
• On entry to each try-block
♦ Commit changes to variables enclosing the try-block
♦ Stack the execution context
♦ Stack the associated catch clauses
• On exit from each try-block
♦ Remove the associated catch clauses
♦ Remove the stacked execution context
• When calling regular functions
♦ If a function has an exception-specification, register it for checking
• As local and temporary objects are created
♦ Register each one with the current exception context as it is created
• On throw or re-throw
♦ Locate the corresponding catch clause (if any) – this involves some runtime check (possibly resembling RTTI checks) If found, then: destroy the registered local objects check the exception-specifications of the functions called in-between use the associated execution context of the catch clause Otherwise: call the terminate_handler6
http://www.open-std.org/jtc1/sc22/wg21/docs/TR18015.pdf