search

Home  >  Q&A  >  body text

java - Generally speaking, does a service need to throw exceptions to the Controller for handling?

 我一般在项目里,业务层的方法报错都会直接往上抛到控制层来做统一的处理,一般来说,有经验的开发者会选择这样的异常处理方法吗?
如果不这样做,那么一般怎样做?
我想大声告诉你我想大声告诉你2753 days ago673

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-05-17 10:10:28

    Why should we throw it into the control layer? Different field types will affect your business direction, so I usually unified convergence exceptions at the service layer.

    reply
    0
  • 怪我咯

    怪我咯2017-05-17 10:10:28

    When there is a transaction, I will throw the exception to the control layer for processing, otherwise it may affect the rollback of the transaction

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-17 10:10:28

    Usually it is handled directly in the service

    reply
    0
  • Cancelreply