+ Start a Discussion

Scheduled Batch Job Exception Handling

I've created a Batchable class that also implements Schedulable.  I can get it to work but I have concern about receiving the errors should there be problems.    I can send an email in the finish() method, but that will only give me a summary of the total batch jobs and the first abbreviated error message (if there was one).  How can I see the actual exception messages for each of the batches in the job (ie. if 2 of the 6 total batches failed, I would like 2 emails with the exception.getMessage(), or one large summary email with each exception message)?


I tried wrapping my code in the 'execute(Database.BatchableContext bc, List<sObject> objects)' method in a try/catch but it doesn't seem to catch anything.  In the 'catch()', I wrote code to email me the exception.getMessage().  Looking at the Apex Jobs screen, I can see that some of the batches are failing, but I don't receive any emails.


Is there anyway I can see the exception for each failed batch in a scheduled  job?  It's very hard to debug if I can't see the actual exceptions that are being thrown for a scheduled batch job.