Exceptions for flow of control

后端 未结 7 617
死守一世寂寞
死守一世寂寞 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:20

    walk_r should simply return the value when it is hit. It's is a pretty standard recursion example. The only potential problem I see is that you said it is potentially endless, which will have to be compensated for in the walk_r code by keeping count of the recursion depth and stopping at some maximum value.

    The exception actually makes the coding very strange since the method call now throws an exception to return the value, instead of simply returning 'normally'.

    try
    {
        Walk_r(tree);
    }
    catch (SuccessException ex)
    {
        result = ex.Value;
    }
    

    becomes

    result = Walk_r(tree);
    

提交回复
热议问题