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
Praveen Venkata BPraveen Venkata B 

How to create Exception for Apex manual share class in test class with 100% code coverage

Help me in creating test class for below class with 100% code coverage. I have done User creation part in test class. Let me know how to create exception in test class for below class:

Below is the hierarchecal share class:
public without sharing class  UserForm_ManagerHierarchyHandler{

    List<User_form__Share> listOfUserformShare = new List<User_form__Share>();
    
    //Method to retrieve the manager's up the hierarchy
    public void retrieveManagerHierarchy(User_form__c  userFormRecord){
        String accessLevel = 'edit';
        try{
            Id UFOwnerId = userFormRecord.Employee__c;
            
            if(UFOwnerId !=NULL){
                User newUser = new User();
                newUser = [SELECT Id,managerId from User where Id=:UFOwnerId ];
                if(newUser.managerId!=NULL){
                    do{
                        SharingProcess(newUser,userFormRecord,accessLevel );
                        Id managerId = newUser.managerId;                        
                        newUser = [Select Id,managerId from User where Id=:managerId ];
                        accessLevel = 'read';
                    }        
                    while(newUser.managerId!=NULL);
                }
                
                if(listOfUserFormShare .size()>0){
                    Database.Insert(listOfUserFormShare,false);
                }
            }
        }
        catch(Exception e){
        }
    }
    
    
    // Method to share the record to Manager's up in the Hierarchy
    public void sharingProcess(User newUser, User_Form__c newUserForm,String Access){
        User_form__Share newUserFormShare = new User_form__Share();
        newUserFormShare.parentId = newUserForm.Id;
        newUserFormShare.AccessLevel = Access;
        newUserFormShare.UserOrGroupId = newUser.managerId;
        listOfUserFormShare.add(newUserFormShare);  
    }
}