0
我已經拋出一個std::ios_base::failure
並試圖抓住它,在C++ 11模式中使用鐺4.0以下示例代碼:爲什麼叮噹4.0不捕捉std異常?
#include <ios>
#include <iostream>
#include <stdexcept>
int
main()
{
try {
throw new std::ios_base::failure("Bonkers");
}
catch(std::ios_base::failure &e) {
std::cout << "Failure " << e.what() << std::endl;
}
catch(...) {
std::cout << "Anything" << std::endl;
}
return 0;
}
予編譯程序這樣的:
clang++-4.0 --std=c++11 -g -W -Wall ex.cc -o ex
而我得到的輸出:
Anything
我會期待它捕捉到特定的異常。我嘗試了g ++ 5.4,但結果相同。也嘗試沒有C + + 11標誌,也沒有幫助。拿出catch all條款給我這個:
terminate called after throwing an instance of 'std::ios_base::failure[abi:cxx11]*'
那麼我錯過了什麼,我能做些什麼來解決這個問題?當我不使用C++ 11標誌時,abi:cxx11也顯示出來。
你正在拋出一個'std :: ios_base :: failure *'並試圖捕獲一個'std :: ios_base :: failure'。那些不是同一類型。 – nwp
更改'拋出新的std :: ios_base :: failure(「Bonkers」);'拋出std :: ios_base :: failure(「Bonkers」);' –
你的意思是拋出std :: ios_base :: failure(「 Bonkers「);' –