Should I inherit from std::exception?

前端 未结 14 1499
有刺的猬
有刺的猬 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:32

    The main benefit is that code using your classes doesn't have to know exact type of what you throw at it, but can just catch the std::exception.

    Edit: as Martin and others noted, you actually want to derive from one of the sub-classes of std::exception declared in header.

提交回复
热议问题