Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V2673. MISRA. An empty throw should...
menu mobile close menu
Additional information
toggle menu Contents

V2673. MISRA. An empty throw should only occur within the compound-statement of a catch handler.

Jul 30 2026

This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.

This diagnostic rule is relevant only for C++.

The analyzer has detected that the throw expression has no operand (rethrowing the active exception) and is not located inside a catch block. Such code may contain an error. A throw; statement outside the explicit syntactic boundaries of a catch handler is a sign of a potential defect. If the code is executed while there are no active exceptions in the program, the std::terminate function will be invoked, causing the program to crash.

The example:

try
{
  if (ok)
    return ....;

  throw;
}
catch (...)
{
}

In this example, the throw expression is executed within the try block, where no exception has yet been caught. Since the exception object for the throw is missing, executing this code results in the std::terminate function invocation.

The fixed code:

try
{
  if (ok)
    return ...;

  throw some_exception(....);
}
catch (...)
{
}

What a quick draw in the Wild West of Coding —
you caught the bug in sec!
But we catch them in milliseconds. How about a duel?

Try free