Код: Выделить всё
// MailBuilder: builder class for containing various email-related values
public void sendEmails(MailBuilder mailBuilder) {
Message msg = new SMTPMessage(Session.getInstance(presetProperties));
try {
msg.setContent(mailBuilder.body);
msg.setRecipients(RecipientType.TO, mailBuilder.to);
msg.setRecipients(RecipientType.CC, mailBuilder.cc);
msg.setRecipients(RecipientType.BCC, mailBuilder.bcc);
msg.setSubject(mailBuilder.subject);
} catch (MessagingException e) {
throw new IllegalArgumentException("Malformed email", e);
}
// ...send email
}
Код: Выделить всё
MessagingException collectedExceptions = null;
try {
msg.setContent(mailBuilder.body)
} catch (MessagingException e) {
if (collectedExceptions == null) collectedExceptions = e;
else collectedExceptions.addSuppressed(e);
}
try {
msg.setSubject(mailBuilder.subject);
} catch (MessagingException e) {
if (collectedExceptions == null) collectedExceptions = e;
else collectedExceptions.addSuppressed(e);
}
// repeat for other methods
if (collectedExceptions != null) throw collectedExceptions;
Подробнее здесь: https://stackoverflow.com/questions/790 ... s-into-one
Мобильная версия