Exceptions in IBM MQ classes for JMS
An IBM MQ classes for JMS application must handle exceptions that are thrown by JMS API calls or that are delivered to an exception handler.
IBM MQ classes for JMS reports runtime problems by throwing exceptions. The type of exceptions that are thrown, and the way that these exceptions must be handled, depends on the version of the JMS specification that is used by the application:- Methods on the interfaces that are defined in JMS 1.1 and earlier throw checked exceptions. The base class of these exceptions is JMSException. For more information about how to handle checked exceptions, see Handling checked exceptions.
- Methods on the interfaces added in JMS 2.0 throw unchecked exceptions. The base class for these exceptions is JMSRuntimeException. For more information on how to handle unchecked exceptions, see Handling unchecked exceptions.
We can also register an ExceptionListener with a JMS Connection or a JMSContext. The MQ classes for JMS then notify the ExceptionListener if either an issue is detected with a connection to the queue manager, or if an issue occurs while trying to deliver a message asynchronously. For more information, see ExceptionListeners.
- Handling checked exceptions
Methods on the interfaces that are defined in JMS 1.1 or earlier throw checked exceptions. The base class for these exceptions is JMSException. Therefore, catching JMSExceptions provides a generic way of handling these types of exceptions. - Handling unchecked exceptions
Methods on the interfaces that are defined in JMS 2.0 throw unchecked exceptions. The base class for these exceptions is JMSRuntimeException. Therefore, catching JMSRuntimeExceptions provides a generic way of handling these types of exceptions. - ExceptionListeners
JMS Connection and JMSContext objects have an associated connection to a queue manager. Your application can register an ExceptionListener with a JMS Connection or JMSContext. If a problem occurs that makes the connection that is associated with the Connection or JMSContext unusable, the IBM MQ classes for JMS delivers an exception to the ExceptionListener by calling its onException() method. Your application then has the opportunity to reestablish the connection.
Parent topic: Writing IBM MQ classes for JMS applications
Related information