簡體   English   中英

捕獲塊使我無法匹配操作員錯誤

[英]catch block gives me no match for operator error

我正在嘗試捕獲如下異常-

try {

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

但是每次我遇到這個錯誤時-

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

知道我在這里做什么錯嗎?

用這個

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

<<運算符不會在exception類中重載。

編譯器(試圖)告訴您未聲明operator<<(std::ostream&, std::exception const&)

符合std::exception運算符<<沒有重載。 使用ex.what()代替。 what()返回一個<<理解的char* 參考: http : //www.cplusplus.com/reference/exception/exception/what/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM