Handling Exceptions in ejbCreate


EJB programming & troubleshooting: Handling Exceptions in ejbCreate

  1. Handling Exceptions in ejbCreate (2 messages)

    What is exactly the difference between throwing CreateException and RemoteException in ejbCreate?

    Should I throw any custom Exception from ejbCreate instead of CreateException?


    Threaded Messages (2)

  2. You can not do this as you will break the EJB Specs.
  3. There are three seperate issues here:
    1. Should I throw a RemoteException from ejbCreate (or anything else)?
    Prefferably not. This was allowed in EJB1.0 and is still legal for compatibility reasons, but is deprecated since EJB1.1.
    2. What would be the difference (in terms of the effect) between throwing a CreateException and a RemoteException?
    A RemoteException is a system exception, while a CreateException is an application exception (see 3). System exception have all sorts of side effects, like rolling back the caller transaction and discarding the throwing instance. You may want these side effects in some cases, but a better way to cause them is to throw a different non-deprecated system exception like EJBException or some other RuntimeException.
    An application exception has less side effects, and is what you normally want. See 3.
    3. What exactly does CreateException mean in the EJB spec? (regarding your last question)
    CreateException is a normal application exception as far is it's side effects go. It is a mere convinience, and the only rule that specially addresses it you should know of is that it must be declared to be thrown by a create method.
    Your create method may declare (and throw) other application exceptions if you please, and may also throw system exceptions (don't declare these). As a matter of style, exceptions that are directly related to the creation process should use CreateException to make the code readable, but there is no rule saying you must do that.