Note: I can't use anything that is default.
I am trying to make a very simple exception handling routine or at the very least make something that looks the part. I don't want to do very much, just throw an exception and print an error message.
in .h
class MyException {
protected: string message;
public:
MyException (string mes) {
this->message = mes;
}
MyException (); // is this necessary ? does it do anything ?
string getMessage() const {
return this->message;
}
};
What I'd want is to have a "PersonException" and "ActivityException". Might use a template but not sure if that would work out.
class PersonException:public MyException {
public:
PersonException (string message):MyException(message) {
}
};
class PersonValidator {
public:
PersonValidator (Person p) throw (PersonException);
};
in .cpp
void PersonValidator::PersonValidator(Person p) throw (PersonException) {
if (p.getPhone < 0) {
throw PersonException ("Person Number is invalid");
}
What here is wrong or cumbersome, how could it be done better ? and where do I actually print the error message ?