1

I am trying to catch the exception like below -

try {

} catch (const std::exception& ex) {
    cout << "An exception occurred when executing query. " << ex << endl;
}

But everytime I am getting this error -

no match for operator<< in std::operator<< <std::char_traits<char> >((* & std::cout), ((const char*)"An exception occurred when executing query. ")) << ex

Any idea what wrong I am doing here?

4

3 回答 3

3

用这个

cout << "An exception occurred when executing query. " << ex.what() << endl;

运算符在类<<中没有重载。exception

于 2013-10-16T17:47:41.443 回答
1

编译器(试图)告诉你 anoperator<<(std::ostream&, std::exception const&)没有声明。

于 2013-10-16T17:49:32.640 回答
1

<<匹配的运算符没有重载std::exception。改为使用ex.what()what()返回一个char*明白<<的。参考: http ://www.cplusplus.com/reference/exception/exception/what/

于 2013-10-16T17:49:36.977 回答