以下方法(在Visual Studio 2008 ref類中)包含一個我認爲會被捕獲的簡單錯誤 - 但相反它會導致進程中止「Debug Assertion Failed!」。消息框(msg包含有問題的STL向量src行#)。無論是以調試模式還是發佈模式編譯,都會發生這種情況這種情況下的過程是Excel.exe,並且該方法通過COM interop訪問。未捕獲到Visual C++/STL異常
有人能告訴我爲什麼這個錯誤不會被困住嗎?
String^ FOO()
{
try {
std::vector<int> vfoo;
vfoo.push_back(999);
return vfoo[1].ToString(); //!!!! error: index 1 not valid
}
catch(std::exception& stdE) { // not catching
return "Unhandled STL exception";
}
catch(System::Exception^ E) { // not catching
return "Unhandled .NET exception: " + E->Message;
}
catch(...) { // not even this is catching
return "Unhandled exception";
}
}
'vfoo [0] .ToString();'........... – perilbrain