Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

question about handling exceptions...

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don�t understand the spec point in page 372(18.2.1:Application exceptions)...

The Bean Provider is responsible for throwing the appropriate application exception from the business
method to report a business logic exception to the client. Because the application exception does not
automatically result in marking the transaction for rollback, the Bean Provider must do one of the following

to ensure data integrity before throwing an application exception from an enterprise bean
� Ensure that the instance is in a state such .....
� Mark the transaction for rollback using the EJBContext.setRollbackOnly() method

why i mut mark the transaction for rollback?... if i though one application exception should not rollback a transaction.

by the way...

why do i must declare a application exception (like a FinderException) in a bussines method into a bean class if i can handle it, or why do i must re-throw it, when i handled by a try/catch block?

can anybody help me to oundertand it?
Cowgirl and Author
Posts: 1589
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy --
I think in this case the spec is saying something like:

* When you throw an application exception, only YOU can decide if that exception can still allow the transaction to continue successfully, or if the transaction must be rolled back.

* IF you decide that the transaction must be rolled back, YOU must invoke setRollbackOnly(), because the Container does not roll transactions back for application exceptions (since it gives you--the bean provider--the choice).

So you do not have to mark the transaction for rollback unless you decide that the transaction should not complete successfully.

You do not have to rethrow an exception that you handle... only those that you decide you cannot recover from. Some exceptions must be defined because the Container may choose to subclass your bean class, and the subclass must be allowed to throw those exceptions to the Container, but it depends on the scenario and bean type, etc....

Hope that helps with *part* of your question.

Eduardo Alcazar
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh thank yo very much Kathy, i already understood now , by the way... i'm a big fan of you, your books are incredible... (i�ve read two, including HFEJB & i've pre-order HFS&JSP)

you�re the best
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic