title: How to handle @Async in Spring boot
body: <pre><code>public class ServiceImpl{
  
      @Autowired
      EmailService emailService;
  
      public void arr() throws Exception
      {
          int[] arr={1,2,3,4};
          for(int i=0;i&lt;arr.length+1;i++)
          {
              System.out.print(i+" ");
          }
          emailService.sendMail("Subject of mail","body of mail","xuz@gmail.com","abc@gmail.com");
      }
  }
  
  
  @EnableAsync
  public class EmailService {
      @Async
      public void sendMail(String subject,String body,String from,String to)
      {
          //Implementation of sendMail function
      }
  }
  </code></pre>
  
  <p>I have used @Async annotation in the email service for triggering the mail, if any error occurs in the caller method the mail is getting triggered irrespective of any exceptions in the caller method.</p>
  
  <p>I don't want the email method to get executed after the error occurs in the caller method. how can i handle this?</p>
  
  <p>In the above example the for loop throws arrayIndexOutOfBoundException even after the exception occurs the mail will get triggered since it is a async function .
  I don't want the mail to get triggered if exception occurs in arr() method</p>