I am using
catch (Exception e){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'my error msg');
ApexPages.addMessage(myMsg);
}
And have <apex:pageMessages/>
in my VF page.
still i get my custom message + the salesforce standard exception displayed at my page. I want only my message to be shown.
For comment
catch(Exception e){
if(validateVariable.contains('STRING_TOO_LONG') &&
validateVariable.contains('data value too large') ) {
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Character limit exceeded. Please limit your essay in the prescribed character limit');
ApexPages.addMessage(myMsg);
}
Best Answer
The appropriate way to handle this is by creating a custom exception that gets thrown as an inner exception using a utility class. You first catch the exception, then rethrow it, catching it with your custom "inner exception" that produces the error message you'd like to send. Here's an example from the documentation: