在最后两行中获取unhandled exception type MessagingException 。
Eclipse建议我用try catch块覆盖它们。但是当我尝试在互联网上搜索时,他们正在使用这两个语句而没有任何尝试catch块。 所以我想我做错了什么。 怎么解决这个?
MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress("xyz@example.com")); msg.addRecipient(Message.RecipientType.TO, new InternetAddress("abcd@example.com"));Getting error in last two lines that unhandled exception type MessagingException.
Eclipse suggests me to cover them with a try catch block.But when i tried to search in internet they are using these two statement without any try catch block. so i think i am doing something wrong. how to solve this?
最满意答案
你必须有可能解决它。
在代码中添加try-catch-block:
尝试{MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(“xyz@example.com”)); msg.addRecipient(Message.RecipientType.TO,new InternetAddress(“abcd@example.com”));
} catch(MessagingException me){//做某事}
throws MessagingException到方法签名:
public void mymethod throws MessagingException {MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(“xyz@example.com”)); msg.addRecipient(Message.RecipientType.TO,new InternetAddress(“abcd@example.com”)); }
You have to possibilities to solve it.
Add a try-catch- block arround your code:
try { MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress("xyz@example.com")); msg.addRecipient(Message.RecipientType.TO, new InternetAddress("abcd@example.com"));
} catch (MessagingException me){ // do something }
Add throws MessagingException to the method signature:
public void mymethod throws MessagingException { MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress("xyz@example.com")); msg.addRecipient(Message.RecipientType.TO, new InternetAddress("abcd@example.com")); }
更多推荐
发布评论