【发布时间】:2014-04-16 10:40:54
【问题描述】:
在我的 Qt 项目中,我以这种方式处理多个异常:
myExceptions.h:
#ifndef MYEXCEPTIONS_H
#define MYEXCEPTIONS_H
#include <iostream>
#include <exception>
using namespace std;
class myExceptions : public runtime_error
{
public:
myExceptions(const char *msg ) : runtime_error(msg){};
~myExceptions() throw(){};
};
#endif // MYEXCEPTIONS_H
我以这种方式在我的代码中调用异常:
abc.cpp
if (!MyClass::aMethod(a, b) )
{
throw myExceptions("Error message to show");
}
并在我的 main.cpp 中捕获它:
try {
MyClass2 myClass2(param);
} catch (myExceptions &e) {
QMessageBox::critical(&window, "title", e.what());
}
直到这里都没问题,但是当我想在错误消息中显示变量 tmpName 的名称时会发生这种情况。
std::string tmpName;
else{
throw myExceptions("Unrecognized member : " + &tmpName);
}
执行此操作时,出现以下错误:
C2110:'+' : cannot add two pointers.
有人可以帮帮我吗?提前谢谢!
【问题讨论】: