Does C++ have an equivalent to .NET's NotImplementedException?

后端 未结 5 1702
别那么骄傲
别那么骄傲 2020-12-28 13:17

Does the standard library of C++ contain an exception equivalent to .NET\'s NotImplementedException?

If not, what are the best practices to handle incomplete methods

5条回答
  •  臣服心动
    2020-12-28 14:19

    You can inherit from std::logic_error, and define your error message that way:

    class NotImplementedException : public std::logic_error
    {
    public:
        virtual char const * what() const { return "Function not yet implemented."; }
    };
    

    I think doing it this way makes catching the exception more explicit if that's actually a possibility. Reference to std::logic_error: http://www.cplusplus.com/reference/stdexcept/logic_error/

提交回复
热议问题