Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1675

"CX_ROOT" should not be caught

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Narrow this "{{CATCH}}" to a more specific exception exception type
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      ABAP
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min

      Description

      Because CX_ROOT is the base exception type, catching it directly probably casts a wider net than you intended. Catching CX_ROOT could mask far more serious system errors that your CATCH logic was intended to deal with.

      Some smaller, more specific exception type should be caught instead.

      Noncompliant Code Example

        try.
          if ABS( NUMBER ) > 100.
            write / 'Number is large'.
          endif.
        catch CX_ROOT into OREF.
          write / OREF->GET_TEXT( ).
        endtry.
      

      Compliant Solution

        try.
          if ABS( NUMBER ) > 100.
            write / 'Number is large'.
          endif.
        catch CX_SY_ARITHMETIC_ERROR into OREF.
          write / OREF->GET_TEXT( ).
        endtry.
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: