www.pudn.com > allocator.rar > alloc_exceptions.h


// file: alloc_exception.h
// author: Marc Bumble
// July 11, 2002
// Contains classes related to exceptions
// Copyright (C) 2002 by Marc D. Bumble

//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.

//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.

//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef ALLOC_EXCEPTIONS_H
#define ALLOC_EXCEPTIONS_H

// #include 
#include 
#include 
#include 

namespace Alloc_Exception {

  class alloc_exception : public std::exception {
    std::exception exception_val;
    std::string what_str;
  public:
    alloc_exception(std::string val) : exception_val() {
      what_str = val;
    }
    virtual ~alloc_exception() throw () {}
    virtual const char* what() {
      std::cerr << " Allocator Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class alloc_exception

  
  class shm_page_exception : public alloc_exception {
    std::string what_str;
  public:
    shm_page_exception(std::string val) : alloc_exception(val) {
      what_str = val;
    }
    virtual ~shm_page_exception() throw () {}
    virtual const char* what () {
      std::cerr << " Shared Memory Page Fault Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class shm_page_exception

  class ftok_exception : public alloc_exception {
    std::string what_str;
  public:
    ftok_exception(std::string val) : alloc_exception(val) {
      what_str = val;
    }
    virtual ~ftok_exception() throw () {}
    virtual const char* what () {
      std::cerr << " ftok Key Generation Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class ftok_exception

  class shm_exception : public alloc_exception {
    std::string what_str;
  public:
    shm_exception(std::string val) : alloc_exception(val) {
      what_str = val;
    }
    virtual ~shm_exception() throw () {}
    virtual const char* what () {
      std::cerr << " Shared Memory Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class shm_exception

  class mmap_exception : public alloc_exception {
    std::string what_str;
  public:
    mmap_exception(std::string val) : alloc_exception(val) {
      what_str = val;
    }
    virtual ~mmap_exception() throw () {}
    virtual const char* what () {
      std::cerr << " Memory Map Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class mmap_exception

  class fd_exception : public alloc_exception {
    std::string what_str;
  public:
    fd_exception(std::string val) : alloc_exception(val) {
      what_str = val;
    }
    virtual ~fd_exception() throw () {}
    virtual const char* what () {
      std::cerr << " File Descriptor Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class fd_exception

  class sem_exception : public alloc_exception {
    std::string what_str;
  public:
    sem_exception(std::string val) : alloc_exception(val) {
      what_str = val;
    }
    virtual ~sem_exception() throw () {}
    virtual const char* what () {
      std::cerr << " Semaphore Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class sem_exception

  class mem_exhausted_exception : public alloc_exception {
    std::string what_str;
  public:
    mem_exhausted_exception(std::string val) : alloc_exception(val) {
      what_str = val;
    }
    virtual ~mem_exhausted_exception() throw () {}
    virtual const char* what () {
      std::cerr << " Memory Exhaustion Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class mem_exhausted_exception

  class lock_creation_exception : public sem_exception {
    std::string what_str;
  public:
    lock_creation_exception(std::string val) : sem_exception(val) {
      what_str = val;
    }
    virtual ~lock_creation_exception() throw () {}
    virtual const char* what () {
      std::cerr << "Lock Creation Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class lock_creation_exception

  class locking_exception : public sem_exception {
    std::string what_str;
  public:
    locking_exception(std::string val) : sem_exception(val) {
      what_str = val;
    }
    virtual ~locking_exception() throw () {}
    virtual const char* what () {
      std::cerr << "Lock Creation Exception thrown" << std::endl;
      return what_str.data();
    }
  };  // class locking_exception


};  // namespace Alloc_Exception 

#endif