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: 1 rule found
error-handling
    Impact
      Clean code attribute
        1. Catch specific exception types instead of generic "Exception"

           Code Smell

        Catch specific exception types instead of generic "Exception"

        intentionality - clear
        maintainability
        reliability
        Code Smell
        • error-handling

        This rule raises an issue when a try-catch block catches only the generic Exception type without catching more specific exception types first.

        Why is this an issue?

        How can I fix it?

        More Info

        Catching only the generic Exception type makes error handling less precise and harder to maintain. When you catch Exception, you’re handling all possible errors the same way, which can mask important differences between error types.

        Specific exception types like MathException, DMLException, QueryException, and ListException provide valuable information about what went wrong. Each type represents a different category of problem that might need different handling strategies.

        For example, a DMLException might indicate a data validation issue that could be resolved by showing a user-friendly message, while a QueryException might suggest a more serious system problem that requires logging and investigation.

        When you catch specific exceptions first, you can:

        • Provide more targeted error messages to users
        • Apply appropriate recovery strategies for different error types
        • Log different types of errors with appropriate severity levels
        • Make your code’s intent clearer to other developers

        Using only generic Exception catching also makes it harder to identify which specific errors your code might encounter, reducing the effectiveness of testing and debugging.

        What is the potential impact?

        Using generic exception catching can lead to poor error handling, making it difficult to diagnose issues and provide appropriate user feedback. It can also mask serious system problems by treating all errors the same way.

          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use