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

Exception specifications should not be used

    XMLWordPrintable

    Details

    • Message:
      Remove this "throw" clause
    • Highlighting:
      Hide

      throw clause

      Show
      throw clause
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      ExceptionSpecificationUsage
    • Covered Languages:
      C, C++
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1min
    • Analysis Scope:
      Main Sources
    • CppCoreGuidelines:
      E.30

      Description

      Exception specifications never really provided any advantages in C+. They have been deprecated since C11, and removed since C17 (specification with an exception) and C+20 (empty throw specification). If your code still contains some, you should replace empty throw() specifications, with noexcept and remove any other specifications.

      Noncompliant Code Example

      void f() throw(); // Noncompliant
      void g() throw(std::exception); // Noncompliant
      

      Compliant Solution

      void f() noexcept;
      void g();
      

      See

      Exceptions

      If a derived class overrides a function with a dynamic exception specification, then the derived function is forced to add a compatible exception specification. Such exception specifications are ignored.

        Attachments

          Issue Links

          1.
          C-Family RSPEC-5105 Language-Specification Active Unassigned

            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: