#ifndef __EXCEPTIONS_H__ #define __EXCEPTIONS_H__ #ifdef __cplusplus #include #include #include #include #include class GeneralException; char * xstrdup(const char *); void * xmalloc(size_t) throw (GeneralException); void xfree(void *&); void * xrealloc(void *, size_t); int xpipe(int *, int = 0) throw (GeneralException); pid_t xfork() throw (GeneralException); class String; class Base { public: static char * strdup(const char * s) { return xstrdup(s); } static void * malloc(ssize_t s) { return xmalloc(s); } static void * realloc(void * p, size_t s) { return xrealloc(p, s); } static void * calloc(size_t n, size_t s) { return xmalloc(n * s); } void * operator new(size_t s) { return xmalloc(s); } void * operator new(size_t s, void * p) { return memset(p, 0, s); } void operator delete(void * p) { xfree(p); } static void free(void *& p) { xfree(p); } static void free(char *& p) { xfree((void *) p); } static int pipe(int * p, int flag = 0) { return xpipe(p, flag); } static pid_t fork() { return xfork(); } }; class GeneralException : public Base { public: GeneralException(String); GeneralException(const GeneralException &); ~GeneralException(); char * GetMsg(); protected: GeneralException(); char * msg; static char t[BUFSIZ]; }; class MemoryException : public GeneralException { public: MemoryException(ssize_t); }; enum op_t { IO_WRITE = 1, IO_READ }; class IOGeneral : public GeneralException { public: IOGeneral(String); protected: IOGeneral(); }; class IOException : public IOGeneral { public: IOException(String, op_t, ssize_t); }; class IOAgain : public IOGeneral { public: IOAgain(); }; class TaskSwitch : public GeneralException { public: TaskSwitch(); }; #include #else #error This only works with a C++ compiler #endif #endif