[SalesForce] How to over write salesforce standard exception message in catch block

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:

public class MerchandiseException extends Exception {}

public class MerchandiseUtility {
    public static void mainProcessing() {
        try {
            insertMerchandise();
        } catch(MerchandiseException me) {
            System.debug('Message: ' + me.getMessage());    
            System.debug('Cause: ' + me.getCause());    
            System.debug('Line number: ' + me.getLineNumber());    
            System.debug('Stack trace: ' + me.getStackTraceString());    
        }
    }

    public static void insertMerchandise() {
        try {
            // Insert merchandise without required fields
            Merchandise__c m = new Merchandise__c();
            insert m;
        } catch(DmlException e) {
            // Something happened that prevents the insertion
            // of Employee custom objects, so throw a more
            // specific exception.
            throw new MerchandiseException(
                'Merchandise item could not be inserted.', e);
        }
    }
}