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

Exceptions should not be created without being thrown

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Throw this exception or remove this useless statement
    • Highlighting:
      Hide

      The useless statement

      Show
      The useless statement
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      C++
    • Covered Languages:
      C#, Java, JavaScript, PHP, Python, TypeScript
    • Irrelevant for Languages:
      Python, Swift, VB.Net
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Main Sources, Test Sources
    • FindBugs:
      RV_EXCEPTION_NOT_THROWN

      Description

      Creating a new Throwable without actually throwing it is useless and is probably due to a mistake.

      Noncompliant Code Example

      if (x < 0)
        new IllegalArgumentException("x must be nonnegative");
      

      Compliant Solution

      if (x < 0)
        throw new IllegalArgumentException("x must be nonnegative");
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              freddy.mallet Freddy Mallet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: