• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Exception Handling in MDB

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have recently started working in JMS. Can any one help with couple of questions?

1.In onMessage() method , if there is NullPointerException or any arithmetic exception how do you handle it ?

2. While processing message from queue, if there is an error what happens to that message?

Thanks in advance
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear HVA,
Check the EJB 2.1 Specs, Section 18.2.2 (System Exceptions), Page 397. It says:


An enterprise bean business method, message listener method, or container callback method may encounter various exceptions or errors that prevent the method from successfully completing. Typically, this happens because the exception or error is unexpected, or the exception is expected but the EJB Provider does not know how to recover from it. Examples of such exceptions and errors are: failure to obtain a database connection, JNDI exceptions, unexpected RemoteException from invocation of other enterprise beans, unexpected RuntimeException, JVM errors, and so on.
If the enterprise bean method encounters a system-level exception or error that does not allow the method to successfully complete, the method should throw a suitable non-application exception that is compatible with the method�s throws clause. While the EJB specification does not prescribe the exact usage of the exception, it encourages the Bean Provider to follow these guidelines:

  • If the bean method encounters a RuntimeException or error, it should simply propagate the error from the bean method to the container (i.e., the bean method does not have to catch the exception).
  • If the bean method performs an operation that results in a checked exception that the bean method cannot recover, the bean method should throw the javax.ejb.EJBException that wraps the original exception.
  • Any other unexpected error conditions should be reported using the javax.ejb.EJBException.



  • And Section 17.6.3.2 (Required), Page 387:



    A transaction must be started before the dequeuing of the JMS message and, hence, before the invocation of the message-driven bean�s onMessagemethod. The resource manager associated with the arriving message is enlisted with the transaction as well as all the resource managers accessed by the onMessagemethod within the transaction. If the onMessagemethod invokes other enterprise beans, the container passes the transaction context with the invocation. The transaction is committed when the onMessage method has completed. If the onMessagemethod does not successfully complete or the transaction is rolled back, message redelivery semantics apply.

     
    Sheriff
    Posts: 10445
    227
    IntelliJ IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Have a look at the following link:

    http://wiki.jboss.org/wiki/Wiki.jsp?page=FAQJBossMQ
     
    Jaikiran Pai
    Sheriff
    Posts: 10445
    227
    IntelliJ IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This link specifies, that the onMessage method should NOT throw ANY exceptions. This should be caught in the onMessage method and logged
    reply
      Bookmark Topic Watch Topic
    • New Topic