我正在使用 smack 发送聊天消息。在测试时我发现,当网络不可用时,API 不会抛出任何异常。
我的代码:
Chat chat = connection.getChatManager().createChat(
"abc@gmail.com", new MessageListener() {
@Override
public void processMessage(Chat arg0, Message arg1) {
System.out.println(arg1.getFrom() + " says " + arg1.getBody());
}
});
// I Put a break point here and deliberately disable the network.
// But the following line is not throwing the XMPPException
chat.sendMessage("smack says hi.."); /* Send the message  */
我应该添加任何侦听器来捕获异常吗?