I have an Apex Class that has no code in it. But, when I look at the class details, under code coverage, it says that I have 0/6 lines of code not covered. Its parent class is a child class of Salesforce's Exception class (this class also has no code in it and salesforce is able to recognize that giving me a "0% (No coverage data)".

public virtual with sharing class MyException extends Exception { 

   (no code here, don't need coverage)

 public virtual with sharing class CalloutException extends MyException { 

   (no code in here, but Salesforce is showing 0/6 lines of code covered)

I need to have CalloutException at least 75% covered but after playing around with it, could not get a single line in the unit test.

Anyone have any ideas on what's going on?


  • Just incidentally, I'd avoid calling your custom class CalloutException. There is a class with that name in the System namespace. Maybe more a matter of personal preference as it should be separate from your namespace. – Daniel Ballinger Jun 10 '14 at 22:51
  • I think you need to add a constructor to implement the code coverage. – Jair Jun 11 '14 at 2:02

Couldn't you get code coverage by throwing your custom exceptions inside of separate try/catch blocks?

  • 3
    Although technically it shouldn't require coverage, as it has no logic within in. Sometimes what's considered "needing coverage" is a bit indeterminate. – sfdcfox Jun 10 '14 at 19:18

Off hand, my instincts tell me that you likely need to cover the first extended class with test code before you can cover the extended class of the 2nd one. After all, when you pause to think about it, how can you really have covered code of code that extends non-covered code?

I agree with @Greenstork on the general methodology to use to obtain coverage of your code.


Thanks everyone for your quick replies! I managed to solve the issue, so I'll post it here for future reference and for others who may encounter the same issue.

Throwing the custom exception inside try/catch block in the unit test class did not work. I'm not too sure why, but it didn't cover any of the mysterious/invisible 6 lines of code evidently in my blank CalloutException class.

I did not need to cover the extended class with test code (there was nothing to cover in there anyways as it was blank as well).

I tried implementing the default constructor:

public CalloutException() { super(); }

but was prevented from doing so since it is a child class of Exception the default constructor is already implemented by Salesforce.

I tried another constructor implementation:

public CalloutException(String message) { super(message); }

but once again, same issue, being a child class of Salesforce Exception class, that constructor was already implemented.

The solution: I created a dummy constructor

public CalloutException(String internalMessage, String externalMessage) { super(externalMessage); }

I don't intend on using this constructor at all. But after implementing this and running the test code, Salesforce showed the test coverage for this class to be 100% (2/2) (no longer 0/6), so I have full coverage.

So I'm still not too sure why when the class was empty, code coverage was being shown as 0/6, but at least it's working now.


  • the work-around regarding creating another constructor worked for me too - thanks. – rcraven Jul 1 '14 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.