【发布时间】:2012-07-02 13:32:06
【问题描述】:
我需要我的方法来抛出自定义异常
但它一直给我这个错误:error C2059: syntax error : 'string'
我正在阅读以下链接,但它没有解决我的问题:
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 是什么定义的?
-
只是日志,我可以删除它并且错误仍然相同,当我评论 throw(Exception("setDisplayView error")) 一切正常
-
离题了,但是...您只在调用
what()而不是每次抛出它时才记录异常?
标签: c++ exception inheritance