Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.THROW.EMPTY

Empty throw expression does not belong to a catch block.

MISRA-C++ Rule 15-1-3 (required): An empty throw '(throw;)' shall only be used in the compound-statement of a catch handler.

[Implementation 15.3(9), 15.5.1(2)]

Rationale

An empty throw re-throws the temporary object that represents an exception. Its use is intended to enable the handling of an exception to be split across two or more handlers.

However, syntactically, there is nothing to prevent 'throw;' being used outside a catch handler, where there is no exception object to re-throw. This may lead to an implementation-defined program termination.

Example

void f1 ( void )
{
   try
   {
      throw ( 42 );
   }
   catch ( int32_t i ) // int will be handled here first
   {
      if ( i > 0 )
      {
         throw; // and then re-thrown - Compliant
      }
   }
}

void g1 ( void )
{
   try
   {
      f1 ( );
   }

   catch ( int32_t i )
   {
      // Handle re-throw from f1 ( )
      // after f1's handler has done what it needs
   }
}

void f2 ( void )
{
   throw; // Non-compliant
}

void g2 ( void )
{
   try
   { 
      throw; // Non-compliant
   }
   catch ( ... )
   {
      // ...
   }
}