簡體   English   中英

我不知道JMSExceptions是什么,以及如何處理它們。 有人可以向我解釋一下嗎?

[英]I don't know what JMSExceptions are, and how to handle them. Can someone explain this to me please?

我是Java初學者,我不確定JMSExceptions是什么以及他們做了什么,我所看到的一切似乎都是為了讓我能夠深入了解它的真正含義。 我所知道的是它與API有關。

有人可以用簡單的語言向我解釋它是什么嗎?

JMSException是Java消息服務(JMS)包API在需要將異常傳遞給JMS包的使用者時拋出的基類型(派生自Exception)。

如果您不知道如何在Java中進行異常處理,那么來自Sun的這一特色可能是一個良好的開端。

有很好的示例說明如何使用JMS API以及如何在這里捕獲JMSExceptions - 突出的位是:

/**
   This method is called asynchronously by JMS when a message arrives
   at the topic. Client applications must not throw any exceptions in
   the onMessage method.
   @param message A JMS message.
 */
public void onMessage(Message message)
{
    TextMessage msg = (TextMessage) message;
    try {
        System.out.println("received: " + msg.getText());
    } catch (JMSException ex) {
        ex.printStackTrace();
    }
}

/**
   This method is called asynchronously by JMS when some error occurs.
   When using an asynchronous message listener it is recommended to use
   an exception listener also since JMS have no way to report errors
   otherwise.
   @param exception A JMS exception.
 */
public void onException(JMSException exception)
{
    System.err.println("something bad happended: " + exception);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM