I have an exception class:
#ifndef OBJECTEXCEPTION_H_
#define OBJECTEXCEPTION_H_
class ObjectException: public std::logic_error
{
public:
ObjectException (const std::string& raison)
:std::logic_error(raison){};
};
class Object1Exception: public ObjectException
{
public:
Object1Exception (const std::string& raison)
: ObjectException(raison){};
};
#endif
I have a method which throw this exception:
void Object1::myMethod(int type) {
if (type == 0) {
throw new Object1Exception(type);
}
...
}
Now I use this method:
try{
obj1->myMethod(0);
}
catch(Object1Exception& error){
}
But I have this error
terminate called after throwing an instance of 'tp::Object1Exception*'
I don't understand why the exception is not caught.
newin C++ unless you're an expert.