Hello everyone,
Such code segment is used to check whether function call or exception-handling mechanism runs out of memory first (written by Bjarne),
1.Code:void perverted() { try{ throw exception(); } catch (exception& e) { perverted(); cout << e.what() << endl; } }
My question is when the exception is thrown, and goes to exception handler in catch block, it will do operations in the following sequences,
(1) execute the exception handler code (since there will be recursive function call -- stack will ever increasing);
(2) unwind stack.
Runs out of memory because function call will make stack ever-increasing, right?
If it does (2) before (1), I think stack will always be unwinded before exception handling is called -- then stack will never grow, so there will be no out-of-memory caused by an ever increasing stack.
Is that correct?
2.
I am confused about why exception handling mechanism will run out of memory because in exception handle implementation, we just insert exception handler registration block of the function onto the beginning of the new function call stack each time there is a function call, so the memory should be the memory consumed by function call stuff, I do not think exception handling mechanism itself will consume additional memory. How do you think of it and how do you think of the what are the memory consumed by exception handling mechanism?
thanks in advance,
George