Why is this Exception not being caught?
I read that System.LimitException is not caught but didn't see anywhere about System.FinalException.
Non-Working Code
@AuraEnabled
public static List<RecordType> getRecordTypes() {
try {
String sObjectType = 'Task';
List<RecordType> recordTypes = RecordTypeRepository.getBySObjectType(sObjectType);
return removeGenericTaskRecordType(recordTypes);
} catch (Exception e) {
String message = ErrorMessage.formatExceptionMessage(e, 'There was an error running NewTaskFormController getRecordTypes.');
System.debug(message);
throw new AuraHandledException(message);
}
}
public static List<RecordType> removeGenericTaskRecordType(List<RecordType> recordTypes) {
RecordType genericTask = RecordTypeRepository.getById(RecordTypeRepository.GENERIC_TASK_ID);
Integer genericTaskIndex = recordTypes.indexOf(genericTask);
for (RecordType recordType: recordTypes) {
recordTypes.remove(genericTaskIndex );
}
return recordTypes;
}
What I've Tried
- The same code structure (try-catch) just a different exception and it does get caught.
"common.apex.runtime.impl.ExecutionException: List index out of bounds: -1
Working-Code Example
public static List<RecordType> removeGenericTaskRecordType(List<RecordType> recordTypes) {
RecordType genericTask = RecordTypeRepository.getById(RecordTypeRepository.GENERIC_TASK_ID);
Integer genericTaskIndex = -1;
recordTypes.remove(genericTaskIndex);
return recordTypes;
}