home *** CD-ROM | disk | FTP | other *** search
- #ifndef EXCEPT_H
- #define EXCEPT_H
-
- // Get needed include files
- #include <eh.h>
- #include <afx.h>
-
- // Error codes
- typedef enum {
- EXP_NO_ERROR,
- EXP_GENERIC_ERROR,
- EXP_ERR_EXPENSE_TOO_SMALL,
- EXP_ERR_EXPENSE_TOO_LARGE,
- EXP_ERR_NO_EXPENSE_ITEMS,
- EXP_ERR_TOO_MANY_EXPENSE_ITEMS,
- EXP_ERR_TOTAL_EXPENSE_TOO_LARGE
- } ErrorCode;
-
- // Our base exception class
- class ExpException {
- public:
- ExpException(ErrorCode NewErrorCode,
- const char *NewReason = NULL) :
- TheError(NewErrorCode),
- TheReason(NewReason)
- { }
-
- void SetErrorCode(ErrorCode NewErrorCode)
- { TheError = NewErrorCode; }
- void SetReason(const char* NewReason)
- { TheReason = NewReason; }
-
- CString Why() const { return TheReason; }
- ErrorCode GetErrorCode() const { return TheError; }
-
- private:
- CString TheReason;
- ErrorCode TheError;
- };
-
- // Specific exception classes
- class ExpenseTooSmall : public ExpException
- {
- public:
- ExpenseTooSmall() :
- ExpException(EXP_ERR_EXPENSE_TOO_SMALL,
- "Expense item under the minimum amount eligible "
- "for reimbursement.")
- { }
- };
-
- class ExpenseTooLarge : public ExpException
- {
- public:
- ExpenseTooLarge() :
- ExpException(EXP_ERR_EXPENSE_TOO_LARGE,
- "Expense item greater than the maximum amount "
- "eligible for reimbursement.")
- { }
- };
-
- class EmployeeException : public ExpException
- {
- public:
- EmployeeException(ErrorCode NewErrorCode,
- unsigned NewEmployeeID,
- const char *NewReason = NULL) :
- ExpException(NewErrorCode, NewReason),
- EmployeeID(NewEmployeeID)
- { }
- unsigned GetEmployeeID() const { return EmployeeID; }
- private:
- unsigned EmployeeID;
- };
-
- class NoExpenseItems : public EmployeeException
- {
- public:
- NoExpenseItems(unsigned NewEmployeeID) :
- EmployeeException(EXP_ERR_NO_EXPENSE_ITEMS,
- NewEmployeeID,
- "No expense items for this employee")
- { }
- };
-
- class TooManyExpenseItems : public EmployeeException
- {
- public:
- TooManyExpenseItems(unsigned NewEmployeeID) :
- EmployeeException(EXP_ERR_TOO_MANY_EXPENSE_ITEMS,
- NewEmployeeID,
- "Too many expense items for this employee")
- { }
- };
-
- class ExpenseTotalTooLarge : public ExpException
- {
- public:
- ExpenseTotalTooLarge() :
- ExpException(EXP_ERR_TOTAL_EXPENSE_TOO_LARGE,
- "Expense total greater than maximum amount "
- "eligible for reimbursement.")
- { }
- };
-
- #endif
-