Do you consider this technique “BAD”?

前端 未结 28 1441
借酒劲吻你
借酒劲吻你 2021-02-02 10:57

Sometimes you need to skip execution of part of a method under certain non-critical error conditions. You can use exceptions for that, but exceptions generally are not

28条回答
  •  臣服心动
    2021-02-02 11:32

    This is convoluted and confusing, I would scrap it immediately.

    Consider this alternative:

    private void DoSomething()
    {
       // some code
       if (some condition)
       {
          return;
       }
       // some more code
       if (some other condition)
       {
          return;
       }
       // yet more code
    }
    

    Also consider breaking up the code above into more than one method.

提交回复
热议问题