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
SFDC_LearnerSFDC_Learner 

code coverage

Code coverage for this class:

 

public class catchtest

{
    public void m1()
    {
        integer i=10,j=0,d;
        try
        {
            d=i/j;
            // some statements
        }
        catch(Exception e)
        {
                       //some statements
        }

How can i conver the code, when i have try and catch block in my class.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
VVNRAOVVNRAO
public class catchtest
{
    public Integer i{get;set;}
    public Integer j{get;set;}
    public void m1()
    {
        
        Integer d;
        try
        {
            d=i/j;
            system.debug('******** D ********'+d);
        }
        catch(Exception e)
        {
            String result=String.valueof(e);
            system.debug('******* Exception is **'+Result);
        }
        
    }
    static testmethod void testm1()
    {
       catchtest obj1=new catchtest();
       obj1.i=20;
       obj1.j=0;
       obj1.m1();
       obj1.i=20;
       obj1.j=10;
       obj1.m1();
       
    }
}