C++ Logo

std-proposals

Advanced search

not_implemented exception

From: Sergey Buslov <sergey.buslov_at_[hidden]>
Date: Fri, 19 Nov 2021 11:17:21 +0000
Hi All,

I'd like to propose adding *'not_implemented'* exception to C++ exception
stack to make it easier for developers to manifest their intentions and
de-clutter code from ever growing TODO comments that are easily forgotten.

Such exceptions would remind developers to add missing bits of
functionality if the tests/users are trying to use the feature that hasn't
yet been implemented. An alternative approach -- empty function with TODO
comments -- might be easily forgotten and, worse still, silently produce
wrong results when executed.

As a side benefit, this would facilitate test-driven development by
allowing partially implemented code to compile: one may just throw
not_implemented() inside the function regardless of its return type while
they get around implementing it.

There is a downside to it though - the noexcept functions - throwing
not_implemented inside such functions would violate their contracts and
yield unwanted termination and may not even compile if warnings are treated
as error.

Any opinion would be warmly welcome.

Possible implementation:
class not_implemented : public std::logic_error
{
public:
  not_implemented() : std::logic_error("")
    {
    };
   explicit not_implemented(const std::string& what_arg) :
std::logic_error(what_arg)
    {
    };
};

Received on 2021-11-19 05:17:43