Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception Handling in MDB  RSS feed

 
HVA
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Nadeem Awad
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • 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.

     
    Jaikiran Pai
    Sheriff
    Posts: 10447
    227
    IntelliJ IDE Ubuntu
    • Mark post as helpful
    • send pies
    • 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: 10447
    227
    IntelliJ IDE Ubuntu
    • Mark post as helpful
    • send pies
    • 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
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!