background image

JMS Exception Handling

<< JMS Queue Browsers | Writing Simple JMS Client Applications >>
<< JMS Queue Browsers | Writing Simple JMS Client Applications >>

JMS Exception Handling

QueueBrowser browser = session.createBrowser(queue);
See
"A Simple Example of Browsing Messages in a Queue" on page 926
for an example of the use
of a QueueBrowser object.
The createBrowser method allows you to specify a message selector as a second argument
when you create a QueueBrowser. For information on message selectors, see
"JMS Message
Selectors" on page 907
.
The JMS API provides no mechanism for browsing a topic. Messages usually disappear from a
topic as soon as they appear: if there are no message consumers to consume them, the JMS
provider removes them. Although durable subscriptions allow messages to remain on a topic
while the message consumer is not active, no facility exists for examining them.
JMS Exception Handling
The root class for exceptions thrown by JMS API methods is JMSException. Catching
JMSException
provides a generic way of handling all exceptions related to the JMS API.
The JMSException class includes the following subclasses, which are described in the API
documentation:
IllegalStateException
InvalidClientIDException
InvalidDestinationException
InvalidSelectorException
JMSSecurityException
MessageEOFException
MessageFormatException
MessageNotReadableException
MessageNotWriteableException
ResourceAllocationException
TransactionInProgressException
TransactionRolledBackException
All the examples in the tutorial catch and handle JMSException when it is appropriate to do so.
The JMS API Programming Model
The Java EE 5 Tutorial · September 2007
910