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
NandiniNandini 

how to write test class for custom exception ?

Hi Team,

How to write test class for custom exception class ?
public class CustomException extends Exception {
    boolean escape ;
    String errMsg ; 
   public CustomException(String errMsg, boolean escape){
        this.errMsg = errMsg;
        this.escape = escape;
    }
    
    public void addError(String errMsg, boolean escape){
        
    }
    
    
}
Please let me know.

Thanks,
Nandu
 
Raj VakatiRaj Vakati
@isTest
private class CustomExceptionTest {
    static testmethod void testM(){

       
    Test.startTest();
        CustomException  e = new CustomException ('Error', false);
		e.addError('Error', false);
    Test.stopTest();
       
    }   
	
	 
}

 
NagendraNagendra (Salesforce Developers) 
Hi Nandu,

May I suggest you please check with below link from the stack exchange community with a similar issue. Please let us know if this helps.

Thanks,
Nagendra
Bhargavi TunuguntlaBhargavi Tunuguntla
@isTest
public class testclass
{
@isTest
static void testMethod1()
{
Test.startTest();
CustomException ce=new CustomException('test',true);
ce.addError('test',true);
Test.stopTest();

}
}