Source:
<code><START> public Integer addMail(PerunSession sess, ApplicationForm form, ApplicationMail mail) throws PerunException { <END> if (form.getGroup() != null) { if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo()) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, form.getGroup())) { throw new PrivilegeException(sess, "addMail"); } } else { if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo())) { throw new PrivilegeException(sess, "addMail"); } } int id = Utils.getNewId(jdbc, "APPLICATION_MAILS_ID_SEQ"); mail.setId(id); try { jdbc.update("insert into application_mails(id, form_id, app_type, mail_type, send) values (?,?,?,?,?)", mail.getId(), form.getId(), mail.getAppType().toString(), mail.getMailType().toString(), mail.getSend() ? "1" : "0"); } catch (DuplicateKeyException e) { throw new ApplicationMailExistsException("Application mail already exists.", mail); } for (Locale loc : mail.getMessage().keySet()) { try { jdbc.update("insert into application_mail_texts(mail_id,locale,subject,text) values (?,?,?,?)", mail.getId(), loc.toString(), mail.getMessage(loc).getSubject(), mail.getMessage(loc).getText()); } catch (DuplicateKeyException e) { throw new ApplicationMailExistsException("Application mail already exists.", mail); } } log.info("[MAIL MANAGER] Mail notification definition created: {}", mail); if (form.getGroup() != null) { perun.getAuditer().log(sess, new MailForGroupIdAdded(mail,form.getGroup())); } else { perun.getAuditer().log(sess, new MailForVoIdAdded(mail, form.getVo())); } return id; }</code><technical_language>please convert this throw specific exceptions instead of PerunException ? Thank you</technical_language>

Target:
public Integer addMail(PerunSession sess, ApplicationForm form, ApplicationMail mail) throws ApplicationMailExistsException, PrivilegeException { if (form.getGroup() != null) { if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo()) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, form.getGroup())) { throw new PrivilegeException(sess, "addMail"); } } else { if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo())) { throw new PrivilegeException(sess, "addMail"); } } int id = Utils.getNewId(jdbc, "APPLICATION_MAILS_ID_SEQ"); mail.setId(id); try { jdbc.update("insert into application_mails(id, form_id, app_type, mail_type, send) values (?,?,?,?,?)", mail.getId(), form.getId(), mail.getAppType().toString(), mail.getMailType().toString(), mail.getSend() ? "1" : "0"); } catch (DuplicateKeyException e) { throw new ApplicationMailExistsException("Application mail already exists.", mail); } for (Locale loc : mail.getMessage().keySet()) { try { jdbc.update("insert into application_mail_texts(mail_id,locale,subject,text) values (?,?,?,?)", mail.getId(), loc.toString(), mail.getMessage(loc).getSubject(), mail.getMessage(loc).getText()); } catch (DuplicateKeyException e) { throw new ApplicationMailExistsException("Application mail already exists.", mail); } } log.info("[MAIL MANAGER] Mail notification definition created: {}", mail); if (form.getGroup() != null) { perun.getAuditer().log(sess, new MailForGroupIdAdded(mail,form.getGroup())); } else { perun.getAuditer().log(sess, new MailForVoIdAdded(mail, form.getVo())); } return id; }