Should I inherit from std::exception?

前端 未结 14 1474
有刺的猬
有刺的猬 2020-11-30 18:56

I\'ve seen at least one reliable source (a C++ class I took) recommend that application-specific exception classes in C++ should inherit from std::exception. I\

14条回答
  •  [愿得一人]
    2020-11-30 19:31

    Reason for inheriting from std::exception is it "standard" base class for exceptions, so it is natural for other people on a team, for example, to expect that and catch base std::exception.

    If you are looking for convenience, you can inherit from std::runtime_error that provides std::string constructor.

提交回复
热议问题