views:

21

answers:

0

This the function. I dealt with throwing an out_of_range error and can't think of any logic error for this. Any suggestions? Thank you.

int hire(Payroll * p) throw (out_of_range, logic_error){
         // error if no holes left
         if (staffcount == MAX_EMPLOYEES)
                        throw (out_of_range("Hire: Too many employees"));

         // spin down holes looking for a hole.
         for (int i = 0; i < MAX_EMPLOYEES; ++i) {
             Payroll *current = staff[i].get(); // get the pointer

             if (current == 0) { // it is empty
                 appay newpay(p); // convert  *Payrollto auto_ptr
                 staff[i] =newpay;
                 staffcount++; // one more staff
                 return i;      // return index
             } else {
                 // do nothing. Hole is filled
             }
         }
         // should never get here
         if (staffcount > MAX_EMPLOYEES)
         throw (logic_error("no holes, but count ok"));
     }