我有這樣的代碼:覆蓋默認未處理的異常行爲
#include <iostream>
#include <exception>
class TestException : public std::exception
{
public:
char const* what() const throw() override { return msg_.c_str(); }
protected:
std::string & message() throw() { return msg_; }
private:
std::string msg_;
};
void ThrowIt()
{
throw TestException();
}
int main()
{
ThrowIt();
}
建時在任一版本或調試上在程序終止Visual Studio的結果而編制的Windows運行此,同去的時候用GCC在Linux編譯機,結果是:中止
:扔 'TestException'
什麼()的一個實例後終止叫一旦發現未處理的異常,它們都會終止程序。這種行爲是嚴格系統特定的還是由標準規定的?有沒有一種跨平臺的方式,我可以將每個未由
catch
處理的異常重新路由到處理程序,而不是僅僅終止程序?
編輯'的std :: terminate'處理程序不會讓我查看拋出的異常,在第一造成'的std :: terminate'地點,對嗎? –
@JameyD Yup,這就是你從標準中得到的一切。 –