Exceptions for flow of control

后端 未结 7 543
死守一世寂寞
死守一世寂寞 2021-01-20 14:59

There is an interesting post over here about this, in relation to cross-application flow of control.

Well, recently, I\'ve come across an interesting problem. Gener

7条回答
  •  南笙
    南笙 (楼主)
    2021-01-20 15:21

    The issue with using exceptions is that tey (in the grand scheme of things) are very inefficient and slow. It would surely be as easy to have a if condition within the recursive function to just return as and when needed. To be honest, with the amount of memory on modern PC's its unlikely (not impossible though) that you'll get a stack overflow with only a small number of recursive calls (<100).

    If the stack is a real issue, then it might become necessary to be 'creative' and implement a 'depth limited search strategy', allow the function to return from the recursion and restart the search from the last (deepest) node.

    To sum up: Exceptions should only be used in exceptional circumstances, the success of a function call i don't believe qualifies as such.

提交回复
热议问题