java - Why throwing an EJBException is a "recommended" practice? -


I keep this "suggestion" repeatedly from many fellow developers. In my experience I have found that EJBExceptions "Sen of the The world is well suited for the semen perspective (such as when something is wrong then the bean insetation can not cure itself). If an example might be OK, then I think it is better to throw an exception exception.

Here is a pattern that I get repeatedly:

some resource resources; EjbCreate: resource = allocateResource (...); OmMessage: Try {...} Hold (JMSException e) {New EJBException (E); EjbRemove: Open Resource (Resources);

IMHO is an antitrust which causes leakage to the resource.

Edit : Specifically, the EJB specification says that if a bean is a runtime exception (and there is a runtime exception with EJBXation business method), then the bean on it Called without e-pocket.

Is this a relevant example against an EJBException throw? When EJBE expansion should be thrown, what are the related matters?

throwing eJEBE expansion EJB speck (14.2.2 in EJB3) It is recommended in cases where E.J.B. can not be recovered with an exception , the device also claims that the system can properly allow exceptions for the promotion of EJB container.

I agree that such cases will not be enforced by life-cycle callback methods in the container, and therefore your concern is that any resource-arrangement that is typically ejbRemove ( ) is in the callback, it will not be so and therefore the risk of leakage of the resource.

My experience is that due to lack of defensive coding, many problems have arisen. "Position X can not be in a well-behaved system, and if this happens then the whole system breaks down, so I will not give code for that situation." Then we get some "interesting" alignment of the errors of stars and operator and "can not happen" occurs many times in quick succession and there is unrelated side effects kick, which can really be difficult to diagnose the problem.

That is why I will say:

  1. In a situation where everything can be done to leave the example of bean, where the next speak of a business method is capable of working It is possible. This may mean to catch exceptions and stop resources that are in error. In this case you can call those who call you, "Sorry GUV, this request was not working, but maybe you try again later ..." I have a TransientException I do this by leaving the check exception.
  2. If you do not have any important housekeeping in ejbRemove , then you can allow SystemExceptions to progate - but I'm not sure that it is friendly, you have a library And it throws a NullPointerException . Is actually stronger to capture and reinstate TransientException ?
  3. If you have important housekeeping, then I think you need to catch all the exceptions and at least try cleaning you again EJBException or the system exception You can choose to reopen so that the example is destroyed, but at least you have tried to make the house arrangement.

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -