1

I have (inherited) a class MS_exception that is this:

public with sharing class MS_Exception extends Exception {

}

It has zero code coverage. Does it actually do anything? Do I need to cover it?

The only reference I can find to it is another class has the following code:

else {
                throw new MS_Exception('[initFieldNames] Unable to generate JSON for ' + mytarget);
            }

If I delete or comment out the MS_Exception class would this code cease to work? I've tried covering the code by getting this exception to be thrown. But even though that part of the code is covered, the MS_Exception class still has zero coverage.

1 Answer 1

3

If you remove the MS_Exception class, your code will no longer compile. You would need to, at minimum, change the throw new MS_Exception to a different exception type, such as one of the built-in classes, or a different one. Note that the "0% coverage" only implies that there are no lines to cover; try dividing 0/0, you'll understand why most coverage tools will show 0%. However, despite that, this class will deploy just fine.

What an exception does is it immediately goes to the nearest catch from a try-catch block to be handled as an exception. An exception will travel up the call stack (called "unwinding the stack") in order to find the nearest try-catch block that can handle the exception. If no catch block is found and the top of the stack is reached, this causes Salesforce to terminate the transaction and roll back any changes that have been made to the database.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .