Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ApplicationException, when handled

 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine that "CreditException" is an @ApplicationException with the rollback=true element.



If the thrown exception is handled, as shown in the above code, do it cause the active transaction to be marked for the rollback?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel the guy who started the transaction should receive the exception or else, the rollback will not happen. Ranchers, am I right?
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so. Because first it does not make sense, and second how the container knows that you handle an application exception? The container can know when an application exception is thrown, but it is too much to know detail inside a method that what is going on.
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception must be thrown by a business / listener method or its interceptor, the container can then intercept it, check its type and rollback attribute, and take proper action. When you catch it inside your method, consume and not rethrow further, is is as if it was never thrown - the container does not now anything about it.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raf Szczypiorski wrote:The exception must be thrown by a business / listener method or its interceptor, the container can then intercept it, check its type and rollback attribute, and take proper action. When you catch it inside your method, consume and not rethrow further, is is as if it was never thrown - the container does not now anything about it.


Thanks Raf! Nice explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic