• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Are EJB System Exceptions specific?

 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are System Exceptions guaranteed to be specific by the spec? For example, in a NoSuchObject scenario, will the client definitely get a NoSuchObjectException/NoSuchObjectLocalException or could it also get the more generic super clases RemoteException/EJBException? Another example could be a Transaction Required scenario or a Transaction Rolledback scenario. Will the client get the specific TransactionRequiredException/TransactionRequiredLocalException and TransactionRolledbackException/TransactionRolledbackLocalException or could it also get the more generic super classes RemoteException/EJBException ? ie Like application exceptions, are system exceptions too not specific?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think my cheat sheet on exception handling should clear this up. Check it out...
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Valentin,
I had a look at your cheat sheets. They talk about the specific exceptions, but I think they don't answer my question. I got this doubt because in the Exceptions chapter in HFEJB, it says if a client calls the remove() method on a bean after the bean has been removed, it would throw RemoteException to Remote Clients and EJBException to local clients. But this scenario actually qualifies for an NoSuchObjectException / NoSuchObjectLocalException. This is what made me believe that it is up to the container to decide whether to throw the specific NoSuchObjectException or its super class, the generic RemoteException
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by B Sathish:
This is what made me believe that it is up to the container to decide whether to throw the specific NoSuchObjectException or its super class, the generic RemoteException


Use acrobat reader's search function on the EJB 2.0 specification to look for the more specific exceptions. The spec is pretty specific under what circumstances NoSuchObjectException/NoSuchObjectLocalException have to be thrown - and as far as I can see it doesn't give an option to throw a more general exception. I assumed that HFEJB was playing head games to burn in that NoSuchObjectException ISA RemoteException and NoSuchObjectLocalException ISA EJBException - that way you are prepared to select RemoteException when NoSuchObjectException is the right answer but isn't listed or select both answers if "select the two best answers" is specified.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What the cheat sheet tells you is that the only system exceptions a remote bean client is going to ever receive are either TransactionRolledbackException or RemoteException and that local clients wil only have to deal with TransactionRolledbackLocalException or EJBException. Any system exception that the container might throw and that is not in the hierarchy of RemoteException, respectively EJBException, will be wrapped within a RemoteException (for remote client), respectively within an EJBException (for local clients).

The bottom line is that if you receive a generic exception, the real cause for that exception is wrapped inside and you just have to retrieve it and look at it. That way you don't have to spend too much time writing the throws part of your method declaration with a huge number of specific exceptions.

It is worth noting though that RemoveException as well as CreateException, DuplicateKeyException, FinderException and ObjectNotFoundException are application exceptions and NOT system exceptions (EJB 2.1 10.5.9).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic