0
這個簡單的例子在g ++中按預期工作,但在MS VS 2010或2013中顯示錯誤被捕獲之前的運行時庫調試錯誤(無效的分配大小)(單擊忽略然後流經錯誤處理程序正確顯示它是bad_alloc)。
有關VS爲什麼會如此行爲的想法?bad_alloc在VS 2010/2013中搶佔C++
#include <iostream>
#include <exception>
using namespace std;
int main() {
int x;
cout << "Enter -1 for bad_alloc: ";
cin >> x;
try
{
int* myarray = new int[x];
}
catch (exception& e)
{
cout << "Standard exception: " << e.what() << endl;
}
return 0;
}
它只是調試器和/或調試庫,如果你沒有調試器/作爲發佈版本運行它不會。 – wimh 2014-10-26 15:15:08
原來是這樣。以爲我查過了,但我沒有。謝謝。 – 2014-10-26 15:20:18