我需要我的方法拋出自定義異常 但它不斷給我這個錯誤:
error C2059: syntax error : 'string'
C++自定義異常提示錯誤
我在讀下面的鏈接,但它並沒有解決我的問題:
http://msdn.microsoft.com/en-us/library/t8xe60cf%28VS.80%29.aspx
這是我的代碼:
#include <exception>
#include <stdexcept>
#include <string>
#include "Log.h"
LOG_USE()
class Exception : public std::exception
{
public:
explicit Exception(std::string msg)
: message(msg)
{}
~Exception()
{}
virtual const char* what() const throw()
{
LOG_MSG(message) // write to log file
return message.c_str();
}
private:
std::string message;
};
#endif
在我的應用程序
某處我有看起來像這樣的方法:
.....
....
void view::setDisplayView(ViewMode mode) throw(Exception("setDisplayView error"))
{
;
}
....
....
我在做什麼錯在這裏?
我在32位Windows XP上使用Visual Studio 2008。
定義你的LOG_MSG/LOG_USE? – RolandXu
只是記錄,我可以將其刪除,並錯誤還是一樣的,當我發表意見擲(異常(「setDisplayView錯誤」)),每一件事情是工作 – user63898
offtopic,但...您選擇登錄電子異常,只有當'什麼()'被調用,而不是每次拋出? – TeaOverflow