I have written a scheduler class which can schedule a batch job to run every 15 min. I wish to handle a scenario - if there is any exception during scheduling I do not want the chaining of scheduled job to be aborted. The job should keep on getting scheduled even there any error somewhere in the code.
public class abcSchClass implements Schedulable{
Integer timeInterval;
public abcSchClass(Integer timeInterval){
this.timeInterval = timeInterval;
}
public void execute(SchedulableContext sc) {
try{
// Re-schedule
System.debug('Enter Scheduler class');
DateTime now = DateTime.now();
DateTime nextRunTime = now.addMinutes(timeInterval);
String cronString = '' + nextRunTime.second() + ' ' + nextRunTime.minute() + ' ' +
nextRunTime.hour() + ' ' + nextRunTime.day() + ' ' +
nextRunTime.month() + ' ? ' + nextRunTime.year();
System.schedule(abcSchClass.class.getName() + '-' + now.format(), cronString, new abcSchClass(timeInterval));
// Abort the current job
Id jobId = sc.getTriggerId();
System.abortJob(jobId);
// Launch the replacement order batch job
abcbatch b = new abcbatch();
database.executebatch(b);
system.debug('done scheduling');
}
catch(MyExceptionClass e){
}
}
}
I just need to run this code from Execute anonymous and it starts scheduling itself every 15 min. How can I handle the exception here? If there is any error in scheduling the current job then the subsequent scheduling should not be aborted permanently. Also I have built my own custom exception to manager exception. Below is my exception class
public class MyExceptionClass extends Exception {
public MyExceptionClass( Exception e, string sourceClass){
throw(e);
}
}
How can I use this exception class to manage my exception/error scenarios?