When is it OK to use exception handling for business logic?

后端 未结 5 1004
栀梦
栀梦 2020-12-02 22:45

I think it is accepted that as a general rule in Java (and perhaps any language with exception handling) one should try to avoid using exception handling to actually handle

5条回答
  •  难免孤独
    2020-12-02 23:30

    There is a reason exceptions are objects. There is also a reason designers of the Java language split all Throwables into 2 main types: checked and unchecked.

    is it a good idea to rely on an exception happening for certain business logic to occur?

    Yes. Absolutely. You should read Chapter 9 of "Effective Java, Second Edition". It's all there. Nicely explained and waiting for you.

提交回复
热议问题