![ישן](https://static.fresh.co.il/images/vBulletin/statusicon/post_old.gif)
20-06-2010, 21:45
|
![צלמית המשתמש של RP.](image.php?u=47921&dateline=1137858729) |
|
|
חבר מתאריך: 04.11.04
הודעות: 6,986
|
|
שאלה לגבי exception
יש לי class של exceptions שמוגדר באופן הבא:
קוד:
class CellularException : public std::exception {};
class BadRate : public CellularException {};
class BadLineNumber : public CellularException {};
class AccountExists : public CellularException {};
class AccountDoesNotExist : public CellularException {};
class LineExists : public CellularException {};
class LineDoesNotExist : public CellularException {};
class RelativeAlreadyExists : public CellularException {};
class NotAFamilyLine : public CellularException {};
class NoAccounts : public CellularException {};
class NoLines : public CellularException {};
class NoCalls : public CellularException {};
class NoMessages : public CellularException {};
עכשיו אני רוצה לבנות פונקציה שתקבל כל אחד מה-exceptions הנ"ל, ותפעל באופן הבא:
קוד:
catch (bad_alloc& badAlloc) {cout<<"Error: Bad Alloc"<<endl;}
catch (BadRate& badRate) {cout<<"Error: Bad Rate"<<endl;}
catch (BadLineNumber& badLineNumber) {cout<<"Error: Bad Line Number"<<endl;}
catch (AccountExists &accountExists) {cout<<"Error: Account Exists"<<endl;}
catch (AccountDoesNotExist &accountDoesNotExist) {cout<<"Error: Account Does Not Exists"<<endl;}
catch (LineExists& lineExists) {cout<<"Error: Line Exists"<<endl;}
catch (LineDoesNotExist& lineDoesNotExist) {cout<<"Error: Line Does Not Exist"<<endl;}
catch (RelativeAlreadyExists& relativeAlreadyExists) {cout<<"Error: Relative Already Exists"<<endl;}
catch (NotAFamilyLine& notAFamilyLine) {cout<<"Error: Not A Family Line"<<endl;}
catch (NoAccounts& noAccounts) {cout<<"Error: No Accounts"<<endl;}
catch (NoLines& noLines) {cout<<"Error: No Lines"<<endl;}
catch (NoCalls& noCalls) {cout<<"Error: No Calls"<<endl;}
catch (NoMessages& noMessages) {cout<<"Error: No Messages"<<endl;}
למשל שיהיה משהו בסגנון של:
קוד:
try {
newCompany.addAccount ("DD","BB",1);
}
catch (exception& t) {exceptionHandle(t);}
כאשר exceptionHandle היא הפונ' שאמורה לטפל בחריגות...
ניסיתי כמה דרכים אבל די הסתבכתי עם זה.
|