function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DarshanaDarshana 

How to cover Catch block in my test class ?

It covers try block just by calling this method in my testClass but how can i cover my catch block?

public static Boolean funcName(CustObj__c obj){
            //refId will be null
      try{
          CusObj2__c msg = className.fun(id,string);            
          msg.field1 = '1234';
          insert msg;
          return true;
      }catch(Exception Ex){
              throw new InvalidDataException('error msg');
      }
      return false;
    }
Best Answer chosen by Darshana
Raj VakatiRaj Vakati
in test class try like this
 
try{
		ClassName.funcName(NULL ) ;
	}catch(InvalidDataException e){
		
	}

OR  try simply 
 
ClassName.funcName(NULL ) ;