home *** CD-ROM | disk | FTP | other *** search
/ Using Visual C++ 4 (Special Edition) / Using_Visual_C_4_Special_Edition_QUE_1996.iso / ch13 / expsum / expsum2 / except.h next >
Encoding:
C/C++ Source or Header  |  1995-09-18  |  2.4 KB  |  107 lines

  1. #ifndef EXCEPT_H
  2. #define EXCEPT_H
  3.  
  4. // Get needed include files
  5. #include <eh.h>
  6. #include <afx.h>
  7.  
  8. // Error codes
  9. typedef enum {
  10.     EXP_NO_ERROR,
  11.     EXP_GENERIC_ERROR,
  12.     EXP_ERR_EXPENSE_TOO_SMALL,
  13.     EXP_ERR_EXPENSE_TOO_LARGE,
  14.     EXP_ERR_NO_EXPENSE_ITEMS,
  15.     EXP_ERR_TOO_MANY_EXPENSE_ITEMS,
  16.     EXP_ERR_TOTAL_EXPENSE_TOO_LARGE
  17. } ErrorCode;
  18.  
  19. // Our base exception class
  20. class ExpException {
  21. public:
  22.     ExpException(ErrorCode NewErrorCode,
  23.                  const char *NewReason = NULL) :
  24.         TheError(NewErrorCode),
  25.         TheReason(NewReason)
  26.     { }
  27.  
  28.     void SetErrorCode(ErrorCode NewErrorCode)
  29.         { TheError = NewErrorCode; }
  30.     void SetReason(const char* NewReason)
  31.         { TheReason = NewReason; }
  32.  
  33.     CString   Why() const { return TheReason; }
  34.     ErrorCode GetErrorCode() const { return TheError; }
  35.  
  36. private:
  37.     CString   TheReason;
  38.     ErrorCode TheError;
  39. };
  40.  
  41. // Specific exception classes
  42. class ExpenseTooSmall : public ExpException
  43. {
  44. public:
  45.     ExpenseTooSmall() :
  46.         ExpException(EXP_ERR_EXPENSE_TOO_SMALL,
  47.                      "Expense item under the minimum amount eligible "
  48.                      "for reimbursement.")
  49.     { }
  50. };
  51.  
  52. class ExpenseTooLarge : public ExpException
  53. {
  54. public:
  55.     ExpenseTooLarge() :
  56.         ExpException(EXP_ERR_EXPENSE_TOO_LARGE,
  57.                      "Expense item greater than the maximum amount "
  58.                      "eligible for reimbursement.")
  59.     { }
  60. };
  61.  
  62. class EmployeeException : public ExpException 
  63. {
  64. public:
  65.     EmployeeException(ErrorCode NewErrorCode,
  66.                       unsigned NewEmployeeID,
  67.                       const char *NewReason = NULL) :
  68.         ExpException(NewErrorCode, NewReason),
  69.         EmployeeID(NewEmployeeID)
  70.     { }
  71.     unsigned GetEmployeeID() const { return EmployeeID; }
  72. private:
  73.     unsigned EmployeeID;
  74. };
  75.  
  76. class NoExpenseItems : public EmployeeException
  77. {
  78. public:
  79.     NoExpenseItems(unsigned NewEmployeeID) :
  80.     EmployeeException(EXP_ERR_NO_EXPENSE_ITEMS,
  81.                       NewEmployeeID,
  82.                       "No expense items for this employee")
  83.     { }
  84. };
  85.  
  86. class TooManyExpenseItems : public EmployeeException
  87. {
  88. public:
  89.     TooManyExpenseItems(unsigned NewEmployeeID) :
  90.         EmployeeException(EXP_ERR_TOO_MANY_EXPENSE_ITEMS,
  91.                           NewEmployeeID,
  92.                           "Too many expense items for this employee")
  93.     { }
  94. };
  95.  
  96. class ExpenseTotalTooLarge : public ExpException
  97. {
  98. public:
  99.     ExpenseTotalTooLarge() :
  100.         ExpException(EXP_ERR_TOTAL_EXPENSE_TOO_LARGE,
  101.                      "Expense total greater than maximum amount "
  102.                      "eligible for reimbursement.")
  103.     { }
  104. };
  105.  
  106. #endif
  107.