I am attempting to handle exceptions within the context of using a custom object that we have to display error messages. I want to capture any exception or dmlexception messages and use them in the error we are displaying to the user but I only want to handle these if the Exception or DMLException object is not null.
I am getting the following error only when running unit tests:
System.NullPointerException: Argument 2 cannot be null
Here is the line of code that is generating this error:
getErrMsg('CMG_42', null, null);
And here is the function I am using to handle the display of the errors from our custom object:
public void getErrMsg(string errCode, Exception e, DMLException de){
system.debug('DEBUG: err msg map size:' + errMsgMap.size());
system.debug('DEBUG: err msg map --->' + errMsgMap);
if (errMsgMap.size() == 0){
system.debug('DEBUG: err msg map is empty, filling it....');
errMsgMap = utils.LoadErrorMessages();
}
if (e != null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,errMsgMap.get(errCode)+e.getMessage()));
}
else if (de != null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,errMsgMap.get(errCode)+de.getMessage()));
}
else{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,errMsgMap.get(errCode)));
}
}
I am not sure why the unit testing is giving me this error.
getErrMsg
is causing the problem.