לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 20-06-2010, 21:45
צלמית המשתמש של RP.
  משתמש זכר RP. RP. אינו מחובר  
 
חבר מתאריך: 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 היא הפונ' שאמורה לטפל בחריגות...

ניסיתי כמה דרכים אבל די הסתבכתי עם זה.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 04:53

הדף נוצר ב 0.04 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר