public PageId newPage(Page firstpage, int pages) throws 
    BufferPoolExceededException, 
    HashOperationException, 
    ReplacerException,
    HashEntryNotFoundException,
    InvalidFrameNumberException, 
    PagePinnedException, 
    PageUnpinnedException,
    PageNotReadException,
    BufMgrException,
    DiskMgrException,
    IOException {
       
     PageId firstPageId = new PageId();
     allocate_page(firstPageId, pages);
     
     try {
       pinPage(firstPageId,firstpage,true);
    
     // Roll back the pages
     } catch (Exception e) {
       for (int i = 0; i < pages; i++) {
            firstPageId.pid += i;
            deallocate_page(firstPageId);
       } // end for
       return  null;
     } // end try
     
     return firstPageId;
   } // end newPage()