An exception is thrown as a pointer made with new, which handlers for the type do not catch
What it finds
throw new std::runtime_error("..."): the exception thrown is a pointer, which catch (const std::exception&) does not catch, and whose object nobody deletes. C++ exceptions are thrown by value: throw std::runtime_error("...").
From the rule's source, throw_new.rs.
#include <stdexcept> namespace app {void check(int n) { if (n < 0) { throw new std::invalid_argument("negative");tx0 reports: pointer made with new } if (n > 100) { throw (new std::out_of_range("large"));tx0 reports: pointer made with new } if (n == 0) { throw std::invalid_argument("zero"); } auto *error = new std::runtime_error("kept"); delete error;}} // namespace app Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/cpp:throw-new" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/cpp:throw-new] reason="..."tx0 explain tx0/cpp:throw-new shows the same in the terminal. Found a false positive? Report it.