Details
Description
class MyException : public std::exception {}; #include <filesystem> #include <exception> #include <string> void f2(const std::string& _pathToFile) { if (!_pathToFile.empty()) { throw MyException{}; } } void g2() noexcept { // Error: Remove this "noexcept" clause on the function declaration as it can throw. f2("test"); } void f1(const std::filesystem::path& _pathToFile) { if (std::filesystem::exists(_pathToFile)) { throw MyException{}; } } void g1() noexcept { // FN: No issue is raised f1("test"); }
g1 can throw an exception in two different paths:
- when calling std::filesystem::exists
- throw MyException in f1
The first path is not on the user side so we don't raise any issue at all, even though the second path is on the user side.
Attachments
Issue Links
- links to