![Error no matching function for call to 'std::exception::exception(const char [15])' Error no matching function for call to 'std::exception::exception(const char [15])'](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
Error no matching function for call to 'std::exception::exception(const char [15])'
Error 'logic_error' was not declared in this scope
错误原因
C++在使用VS 编译时抛出异常可以用下列语句:
throw std::exception("XXX");
但使用Dev-C++ (GCC) 编译时,会报以下错误:
Error no matching function for call to 'std::exception::exception(const char [15])'
解决方法:
#include <stdexcept>
throw std::logic_error("XXX");
如果不 #include <stdexcept> 则会报错:
Error 'logic_error' was not declared in this scope
附:
标准异常阶层体系
参考:
http://www.cplusplus.com/forum/beginner/107744/
https://blog.****.net/xiajun07061225/article/details/8231270
https://blog.****.net/fengbingchun/article/details/78303734