Catching “Stack Overflow” exceptions in recursive C++ functions

前端 未结 11 1234
暖寄归人
暖寄归人 2020-12-01 16:34

Is it possible to catch a stack overflow exception in a recursive C++ function? If so, how?

so what will happen in this case

void doWork         


        
11条回答
  •  盖世英雄少女心
    2020-12-01 17:38

    You have to know always a level of your recursion and check it if greater than some threshold. Max level (threshold) is calclulated by ratio of stack size divided by the memory required one recursive call.

    The memory required one recursive call is the memory for all arguments of the function plus the memory for all local variables plus the memory for return address + some bytes (about 4-8).

提交回复
热议问题