예제 #1
0
        void Paper::addContent(const std::string& message) {
            int freespace = maxSymbols - symbols;

            try {
                    if (symbols == maxSymbols) {
                        throw OutOfSpace();
                    }
                content += message.substr(0, freespace);
                    if (message.size() + symbols > freespace) {
                    symbols = this->content.size();
                    throw OutOfSpace();
                    }
            symbols = this->content.size();
                } catch (OutOfSpace) {
                    std::cout << "need new Paper" << std::endl;
                }
        }
예제 #2
0
파일: hash.C 프로젝트: emgertz/OOQP
HashTable      *NewHashTable(int size)
{
  int             i;
  HashTable      *table = 0;

  /* allocate a hash table with size equal to a prime greater than size */
  try {
    table = new HashTable;

    if (size > prime[NUMPRIMES - 1]) {
      printf("The size requested for the hash table is too large: %d.\n",
	     size);
      printf("Either add larger primes to the file 'hash.c' or request\n");
      printf("a smaller table.\n");
      OutOfSpace();
    }
    for (i = 0; i < NUMPRIMES; i++)
      if (size < prime[i]) {
	size = prime[i];
	break;
      }
    table->size = size;
    table->list = 0;
    table->list = new ListPtr[size];
    for (i = 0; i < size; i++)
      table->list[i] = NULL;
    
  } catch (...) {
    if( table ) {
      delete [] table->list;
      delete table;
    }
    std::cerr << "Could not allocate the table\n";
    throw;
  }
  return (table);
}