Static Analysis Problem Type Reference
An exception can be thrown that violates the exception specification.
A C++ subroutine can optionally include an exception specification which enumerates the exceptions that can be thrown by that subroutine. This error flags a statement that attempts to throw an exception that is not listed in the exception specification. If this statement is executed, the C++ run time will call the unexpected() function instead. Note: exception specifications are ignored on the Windows* OS host.
|
ID |
Code Location |
Description |
|---|---|---|
|
1 |
Exception throw |
This shows where the exception was thrown |
|
2 |
Definition |
This shows where the subroutine was defined |
#include <stdio.h>
class Legal_Exception
{
public:
const char* message;
explicit Legal_Exception(const char* p) : message(p) { }
};
void I_Only_Throw_Legal_Exceptions() throw(Legal_Exception)
{
// intended to say throw Legal_Exception("My Message");
// This throws "const char *" object instead
throw("My Message");
}
int main(int argc, char **argv)
{
try {
I_Only_Throw_Legal_Exceptions();
}
catch (Legal_Exception & e) {
// Expects to get here, but it won't
printf("Caught legal exception %s\n", e.message);
}
return 0;
}