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

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 {
                } catch (Exception ex) {

    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.