Why throwing an EJBException is a “recommended” practice?

前端 未结 3 1004
悲&欢浪女
悲&欢浪女 2021-02-20 09:10

I keep getting this \"suggestion\" from many fellow developers over and over again. In my experience I\'ve found that EJBExceptions are well-suited for \"end of the world\" from

3条回答
  •  野的像风
    2021-02-20 09:40

    Whether or not is leaks resources depends on how those resources are administered. The discarded bean gets garbage collected giving up its reference to the resource which gets garbage collected in turn when no more references point to it. If the resource is also kept in a collection with a path to root, it will leak unless the container has a pool manager that can detect idle resources and recycle it.

    I agree with you that the bean should handle any exceptions it can by itself and let the result be known to the caller. For me the anti pattern in the situation you describe is using exceptions to pass object state. Exceptions should be exceptions, not used as return values.

提交回复
热议问题