#ifndef __EXCEPTIONS_H__ #define __EXCEPTIONS_H__ #include #include #include #include #include #include #if !defined pid_t && !defined _SYS_TYPES_H typedef int pid_t; #endif #ifdef _MSC_VER #pragma warning (disable:4290) #endif class String; struct ugly_string; class Base { public: virtual ~Base() {}; static char * strdup(const char * s); static void * malloc(ssize_t s); static void * realloc(void * p, size_t s); static void * calloc(size_t n, size_t s); void * operator new(size_t s); void * operator new(size_t s, void * p); void operator delete(void * p); static void free(void *& p); static void free(char *& p); static void free(unsigned char *& p); static int pipe(int * p, int flag = 0); static pid_t fork(); static void exit(int); static void printm(int level, const ugly_string &, ...); static void printm(int level, const char *, ...); static void exception(const String &); static void pushcontext(const String &); static void popcontext(void); static void flushcontext(void); private: static std::vector context; }; class GeneralException : public Base { public: GeneralException(String); GeneralException(const GeneralException &); ~GeneralException(); const char * GetMsg() const; protected: GeneralException(); char * msg; static char t[BUFSIZ]; }; char * xstrdup(const char *); void * xmalloc(size_t) throw (GeneralException); void xfree(void *&); void xfree(char *&); void xfree(unsigned char *&); void * xrealloc(void *, size_t); int xpipe(int *, int = 0) throw (GeneralException); pid_t xfork() throw (GeneralException); void xexit(int) throw (GeneralException); void xexception(const String &) throw (GeneralException); class MemoryException : public GeneralException { public: MemoryException(ssize_t); }; class TaskNotFound : public GeneralException { public: TaskNotFound(); }; 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(); }; class Exit : public GeneralException { public: Exit(int); int GetCode(); private: int code; }; #include #endif