hey i have been getting the same runtime error for a long time which is the exception im throwing is not being caught although i got a catch after its try and here is the code:
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;
}
the IllegalArguments is a class i defined for throwing errors completely nothing special and here is its definition:
#ifndef _ILLEGALARGUMENTS_
#define _ILLEGALARGUMENTS_
#include <iostream>
#include <string>
class IllegalArguments {};
#endif // !_ILLEGALARGUMENTS_
so all of my code compiles very well except for these lines of the main:
try {
*company += NULL;
}
catch (IllegalArguments exp) {
cout << "IllegalArguments exception was thrown !!" << endl;
}
so the project stops at the line of the catch and gives me this error message:
Exception thrown at 0x74C0D722 in Projectinfinity.exe: Microsoft C++ exception: IllegalArguments at memory location 0x0096EA13.
so the idea is that the company is a vector which contains in each index a pointer to an employee which is a class i defined and the operator += is to add an employee to the vector so i check if the pointer to add is null if it is null then i throw an error but apparently it looks like its not working with the catch thing although im throwing an exception by value and catching by value.