MISRAC++2023-18.1.2
In this section:
Synopsis
(Required) An empty throw shall only occur within the compound-statement of a catch handler
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
Unsafe rethrow of exception. This check is identical to MISRAC++2008-15-1-3, THROW-empty.
Coding standards
- MISRA C++ 2008 15-1-3
(Required) An empty throw (throw;) shall only be used in the compound-statement of a catch handler.
Code examples
The following code example fails the check and will give a warning:
#ifndef __EXCEPTIONS
#error "IGNORE_TEST: requires exceptions"
#endif
void func()
{
try
{
throw;
}
catch (...) {}
}
The following code example passes the check and will not give a warning about this issue:
#ifndef __EXCEPTIONS
#error "IGNORE_TEST: requires exceptions"
#endif
void func()
{
try
{
throw (42);
}
catch (int i)
{
if (i > 10)
{
throw;
}
}
}