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
PrajviPrajvi 

Testing exception block when calling another method

Hey Guys!

Although I have >95% code coverage, however, I'd still like to get it to 100% and need some guidance with the following :)

How would you enter the Exception block below via Test Class? Passing an empty string to method1 probably won't work. Any other ideas that would force this to happen?
public class SomeClass {
    
    public static void method1(List<String> strings) {
        List<SObject> sObjects = [Select Id, Name FROM SObject WHERE Id IN :strings];
        if (sObjects.size() > 0) {
            for (SObject sObj : sObjects) {
                try {
                    method2(sObj);
                } catch (Exception ex) {
                    System.debug('***EXCEPTION***');
                    ex.getStackTraceString();
                }
            } 
        }
    }

    public static void method2(SObject sObj) {
        //Do something here
    }
}
Any help would be appreciated. Thanks!
 
emma janeemma jane
I am amazingly charmed with your article. I love the way wherein you form this article. Thankful to you for granting this amazing post to us.
http://officesetups.uk/ 
http://webroot-safe.me/
http://rand-mcnally-gps-update.com
http://garmincomexpress.live/
http://garminexpresss.com/
http://trendmicro-logins.com
http://nortoncomsetupl.com/
http://aolmaill.de
http://norton-comnu16.com/
http://mcafeedownload.de/