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
ChellS @ IndiaChellS @ India 

Is it possible to write a test class for an exception for 100% coverage, as shown below.

global class customException extends Exception {}
Richard Jimenez 9Richard Jimenez 9
ChellS,

You can throw the exception in a test to give you have coverage, but the test proves nothing. What you want is to test the code where you are using (throwing) this exception.

I would also suggest naming the customException to something more specific to the error you are using it for. Create individual custom exceptions for all the exceptions you are throwing. This will then allow you to the catch and identify specific exceptions you are using making it more manageble going forward.

Thanks,
Richard.
Lokeswara ReddyLokeswara Reddy
That can be possible, but you have to make sure your test data will cause your custom exception to be thrown