• Vaibhav Soni 6
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

My entire APEX trigger is wrapped in a try/catch block, catching the generic Exception object, but I'm still hitting a fatal System.LimitException.

 

What's the point of try/catch if it doesn't actually catch an exception? 

How can I make sure my try / catch block prevents a fatal error?

 

Here's the relevant snippet:

 

for (Contact c : [SELECT Email, Id FROM Contact WHERE AccountId = :account_id LIMIT 10]) {
  if(c.Email != null){
    try {
      Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
      message.setTemplateID(email_template.Id);
      message.setWhatId(detail.Id);
      message.setTargetObjectId(c.Id);
      Messaging.sendEmail(new Messaging.SingleEmailMessage[] { message });
    }    

    catch (System.LimitException e) {

      // I don't really care if the email fails.

      // I just don't want it to break my data entry process.

     }

     catch (Exception e) {

      // I don't really care if the email fails.

      // I just don't want it to break my data entry process.
    }
  }

}

 

updated: even explicitly catching system.limitexception fails.