Uncaught exception
An exception is raised from a function but it is not caught and handled
Since R2022b
Description
This defect occurs when a function that is called in main()
raises
an exception and the exception is not handled. Polyspace® highlights the location in the function body where the unhandled exception
is raised and flags the call to the function in main()
. For
instance:
void foo(){ throw std::exception(); //Uncaught exception } int main(){ foo(); //Defect return 1; }
std::bad_alloc
raised by a new
operator remains unhandled.Risk
When an exception remains unhandled, the compiler might invoke the function
std::terminate()
, which terminates the program abruptly. The
abrupt termination does not invoke any exit handlers, does not call the destructors
of the constructed objects, and does not unwind the stack.
Exceptions that are unhandled might result in issues such as memory leaks, security vulnerability, and other unintended behaviors. Poorly designed exception handling process might make your program vulnerable to denial-of-service attacks.
Fix
To fix this defect, design the exception handling in your code to handle expected
and unexpected exceptions. Call functions that are not noexcept
in try
blocks. Handle the exceptions that these functions might
raise by using matching catch()
blocks. Include a
catch-all
block to handle unexpected exceptions.
Examples
Result Information
Group: C++ Exception |
Language: C++ |
Default: Off |
Command-Line Syntax:
UNCAUGHT_EXCEPTION
|
Impact: High |
Version History
Introduced in R2022b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)