我被要求通过继承标准库std :: logic_error异常来创建自定义异常。首先,我试图通过这本书来做事:
class CustomException: public std::logic_error
{
virtual const char* what() const throw()
{
return "Exception raised";
}
};
然后我的同事也接受了这项任务,向我展示了另一种处理这个问题的方法:
class CustomException:public std::logic_error {
using std::logic_error::logic_error;
public:
const static std::string ExceptionText;
};
除了异常消息需要以不同方式传递之外,这两者之间的主要区别是什么?具体来说,我不知道using语句在第二个选项中做了什么。