Main Content

Review and Fix Uncaught Exception Checks

This topic describes how to systematically review the results of an Uncaught exception check in Polyspace® Code Prover™.

Follow one or more of these steps until you determine a fix for the Uncaught exception check. For a description of the check and code examples, see Uncaught exception.

Step 1: Interpret Check Information

Select the check on the Results List pane. On the Result Details pane, view further information about the check.

The message for a red or orange Uncaught exception check typically states one of these reasons.

MessageWhat This Means
Unhandled exception propagates to main or entry-point function.An exception is thrown and not handled in a catch block. The exception escapes to the main.
Call to typeName throws during "catch" parameter construction.Creating the catch parameter invokes a constructor. The constructor throws an exception.
Throw during destructor or delete.A destructor throws an exception.

Step 2: Determine Root Cause of Check

The most common root cause is that an exception propagates up the function call hierarchy from its origin to the main function.

In the event traceback associated with the check, you see the origin of the exception and one path up the function call tree to the main or another entry-point function. Click each event to navigate to the corresponding point in the source code.

In this example, the exception is thrown in the method initialVector::getValue which is called from the main in this sequence:

  • main

  • getValueFromVector

  • initialVector::getValue

The event list shows these points in the code:

  1. The statement that throws an exception.

  2. The return from the function where the exception is thrown, in this case, the initialVector::getValue method.

  3. The return from the next function that the exception propagates to, in this case, the getValueFromVector method.

  4. The main function.

Using this event list, you can trace how the exception escapes and place a try-catch block to handle the exception. For instance, you can place the call:

return vectorPtr->getValue(5)
in a try-catch block. In the catch block, you can catch an exception of type error.