I have some apex code, where I try to upsert a list of records:
try {
upsert recordList Accounts;
} catch (DmlException e) {
//do a loooot of stuff in order to provide a proper error message
//which will be returned to the component
}
Now I built two test scenarios in its respective test class.
The one will be able to upsert the list. Works fine of course.
The other one (which is supposed to cover the catch block) won't because I porpously try to add duplicate values for a unique field. But instead of covering the catch block, the test class run will result into a failed one, becuase it will run into a System.AuraHandledException: Script-thrown exception and return the catch blocks error message in the dev console log, instead of happily cover the catch block.
Is there a way to do it in a cleaner way?
catch
block is designed to bubble up a different exception type? – Adrian Larson♦ Oct 16 '19 at 14:37catch
part is not covered by the test, but instead my test run results into a failed test run. – Cmd_Keen Oct 17 '19 at 8:04