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

前端 未结 11 1216
暖寄归人
暖寄归人 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:25

    Of course, you could avoid the recursion problem by converting it to a loop.

    Not sure if you're aware of this but any recursive solution can be translated to a loop-based solution, and vice-versa. It is usually desirable to use a loop based solution because it is easier to read and understand.

    Regardless of use of recursion or loop, you need to make sure the exit-condition is well defined and will always be hit.

提交回复
热议问题