C++ 在c+中引发但未捕获异常+;
嘿,很长一段时间以来,我一直收到相同的运行时错误,这是我抛出的异常没有被捕获,尽管我在尝试后得到了一个捕获,下面是代码:C++ 在c+中引发但未捕获异常+;,c++,visual-studio,C++,Visual Studio,嘿,很长一段时间以来,我一直收到相同的运行时错误,这是我抛出的异常没有被捕获,尽管我在尝试后得到了一个捕获,下面是代码: Company* Company::operator+=(Employee* emp){ if ((emp == NULL)) { //given a pointer to an element emp we check if the emp is NULL throw IllegalArguments();//we throw an error if it is
Company* Company::operator+=(Employee* emp){
if ((emp == NULL)) { //given a pointer to an element emp we check if the emp is NULL
throw IllegalArguments();//we throw an error if it is null
}
if ((this->contains(emp->getID()) == false)) // we check if the Employee already exists in the Company
_company.push_back(emp->clone());//a method to copy the found element
return this;
}
IllegalArguments是我为抛出错误定义的类,完全没有什么特别之处,以下是它的定义:
#ifndef _ILLEGALARGUMENTS_
#define _ILLEGALARGUMENTS_
#include <iostream>
#include <string>
class IllegalArguments {};
#endif // !_ILLEGALARGUMENTS_
\ifndef\u非法辩论_
#定义非法辩论_
#包括
#包括
类非法辩论{};
#endif/_非法辩论_
所以我所有的代码都编译得很好,除了以下几行:
try {
*company += NULL;
}
catch (IllegalArguments exp) {
cout << "IllegalArguments exception was thrown !!" << endl;
}
试试看{
*公司+=空;
}
捕获(非法辩论实验){
你不能在项目属性中设置“异常中断”(与tablet上的名称不完全一样)吗?按常量捕获是常规的(但不是必需的)。顺便说一下,你的include-guard是一个。