Avoid Losing Exception Information

Impact Area

Manageability

Severity

High

Affected Element

Apex Class

Rule ID #

SF-AVOID-LOSING-EXCEPTION-INFO

Impact #

This rule will generate an issue whenever a try/catch block neither handles nor propagates the exception. Therefore, if any of the following actions are performed inside the catch, the issue should not be raised:

  1. Call a method that consumes/handles the exception (for example, a method that processes the exception).
    This method may receive the exception object directly, or some information extracted from it by calling a method on the exception.

  2. Rethrow the same exception, or throw a new chained exception—i.e., one constructed using the captured exception.

  3. Throw a new exception whose constructor receives information from the captured exception (or data obtained from it by calling a method on the captured exception).

 

Remediation #

Update the code inside the catch block to ensure the exception is either handled properly or propagated in a way that preserves the exception’s information. Avoid patterns that silently suppress the exception without logging, rethrowing, or otherwise processing it.

 

Time to fix #

15 min

Was it helpful ?

THE AI CODE GOVERNANCE BRIEF

Sign up for new updates!