注: デフォルトのものは使用できません。
私は非常に単純な例外処理ルーチンを作成しようとしているか、少なくとも一部に見えるものを作成しようとしています。あまりやりたくないので、例外をスローしてエラーメッセージを出力するだけです。
.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;
}
};
私が望むのは、「PersonException」と「ActivityException」を持つことです。テンプレートを使用するかもしれませんが、それがうまくいくかどうかはわかりません。
class PersonException:public MyException {
public:
PersonException (string message):MyException(message) {
}
};
class PersonValidator {
public:
PersonValidator (Person p) throw (PersonException);
};
.cpp で
void PersonValidator::PersonValidator(Person p) throw (PersonException) {
if (p.getPhone < 0) {
throw PersonException ("Person Number is invalid");
}
ここで間違っていることや面倒なことは何ですか? どうしたらもっとうまくできるでしょうか? エラーメッセージを実際にどこに出力しますか?