I have a custom exception that I throw in a class that is not caught in another class.
I don't know what's wrong here :
Class MailService.java
@Async
public void sendMail(String to, String subject) throws EmailNotSentException {
throw new EmailNotSentException();
}
Class MailResource.java
@RequestMapping(value = "/mails-envoyes",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<MailEnvoye> createMailEnvoye(@RequestBody MailEnvoye mailEnvoye, HttpServletRequest request) throws URISyntaxException {
try{
mailService.sendMail(to, "subject");
}catch (EmailNotSentException e){
log.debug(e.getLocalizedMessage());
}
}
Exception
public class EmailNotSentException extends MessagingException {
public EmailNotSentException() {
super();
}
public EmailNotSentException(String message) {
super(message);
}
public EmailNotSentException(String message, Exception e) {
super(message, e);
}
}