2011-08-01 40 views
2

我在使用visual studio C++編譯器&研究異常處理期間,遇到了許多visual C++編譯器無法支持的功能,如控制異常可以拋出一個函數。 也我無法修改的功能終止()使用set_terminate()。 是它的規範太爲Visual C++修改終止() ... &如果是這樣,那麼任何人都可以解釋這是爲什麼微軟在其編譯器是創造這些規範...: - ?X關於設置set_terminate函數

+0

什麼問題?你不明白爲什麼'set_terminate()'在那裏或什麼? – sharptooth

+0

@sharptooth:我試圖使用set_terminate()來設置terminate(),但它沒有這樣做......我問的原因是什麼 – nobalG

+1

好吧,你究竟做了什麼以及什麼不起作用? – sharptooth

回答

0

什麼你的意思是你無法修改終止

你有沒有試過類似的東西?

// set_terminate example 
#include <iostream> 
#include <exception> 
#include <cstdlib> 
using namespace std; 

void myterminate() { 
    cerr << "terminate handler called\n"; 
    abort(); // forces abnormal termination 
} 

int main (void) { 
    set_terminate (myterminate); 
    throw 0; // unhandled exception: calls terminate handler 
    return 0; 
} 

不要試圖從VS運行。從命令行編譯並執行。

+0

它將在IDE中工作,而不是在調試模式下。 (I.E.選擇Debug菜單 - > Start without debugging。或者按Ctrl + F5) –

+1

我使用VS2008,它在Release模式下也不適用於我。 是否還有其他可能的原因(如在Debug-> Exceptions中設置)? 至少它在VS2008之外工作... –