Do you consider this technique “BAD”?

前端 未结 28 1449
借酒劲吻你
借酒劲吻你 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:48

    If your code is doing something other than the plain meaning of the constructs in place, it's a good sign you've ventured into "cute" territory.

    In this case you have a "loop" that will only run once. Any reader of the code will need to do a double-take to figure out what's going on.

    If the case where it isn't "good" is truly exceptional, then throwing exceptions would be the better choice.

提交回复
热议问题