SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Apex

Apex static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your APEX code

  • All rules 97
  • Vulnerability2
  • Bug26
  • Security Hotspot3
  • Code Smell66
Filtered: 4 rules found
exception-handling
    Impact
      Clean code attribute
        1. DML operations in catch blocks can mask original exceptions

           Bug
        2. Catch blocks should not be empty

           Code Smell
        3. Apex REST services should implement comprehensive exception handling

           Vulnerability
        4. SOQL queries should be assigned to Lists to avoid QueryException

           Bug

        DML operations in catch blocks can mask original exceptions

        intentionality - complete
        reliability
        maintainability
        Bug
        • exception-handling
        • apex
        • salesforce
        • debugging

        This rule raises an issue when DML operations (insert, update, delete, upsert) are performed directly within catch blocks.

        Why is this an issue?

        How can I fix it?

        More Info

        Performing DML operations directly in catch blocks creates a dangerous situation where the original exception can be completely masked.

        When your code encounters an exception, the catch block is meant to handle that error gracefully. However, if you perform a DML operation (like inserting an exception log record) within the catch block, that DML operation can itself fail for various reasons:

        • Missing required fields
        • Validation rule failures
        • Governor limit violations
        • Field-level security restrictions

        When the DML operation fails, it throws a new DmlException that replaces the original exception. This means you lose all information about what actually went wrong in your business logic. Instead of seeing "Account validation failed: Industry is required", you might only see "Exception logging failed: Missing required field Exception_Type__c".

        This makes debugging extremely difficult and can hide critical issues in your application. The original problem remains unfixed while you chase secondary logging failures.

        What is the potential impact?

        The primary risk is loss of critical debugging information. When the original exception is masked, developers cannot identify and fix the root cause of failures.

        This can lead to:

        • Prolonged system issues that remain unresolved
        • Increased debugging time and development costs
        • Poor user experience due to unaddressed underlying problems
        • Potential data integrity issues if business logic failures go unnoticed
          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2025 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use