/* * * Copyright (c) 1995 * Knowledge Science Institute, University of Calgary * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. The Knowledge Science Institute makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ #ifndef MERROR_H #define MERROR_H 1 #ifndef METAUTIL_H #include #endif #if defined(QUICKWIN) || defined(__CONSOLE__) #include #else #ifndef MPLATFORM_H #include #endif #endif #ifndef __STRING_H #include #endif #if defined(_Windows) && !defined(QUICKWIN) && !defined(__CONSOLE__) && !defined(__WINDOWS_H) #include #endif #if defined(_Windows) && !defined(QUICKWIN) && !defined(__CONSOLE__) void METAUTIL_CLASS error(HWND post, char severity, const char _FAR* format, ...); /* post = 0: a window-independent message window, and post to ERROR.LOG = +ve: a window handle for message window parent, and post to ERROR.LOG = -1: post to ERROR.LOG file only severity = 'F': abort program. */ #else void METAUTIL_CLASS error(int post, char severity, const char _FAR* format, ...); /* post = 0 or +ve: post to ERROR.LOG and stderr = -1: post to ERROR.LOG file only severity = 'F': abort program. */ #endif class METAUTIL_CLASS ErrorHandler { public: virtual int postError(char severity, char* errorMessage) = 0; }; //a handy exception class and some handy macros class METAUTIL_CLASS ErrorMsgException { private: char* Msg; public: ErrorMsgException(const char* msg=NULL) {Msg=msg?strdup(msg):NULL;}; //use this constructor if an individual object has a special message ErrorMsgException(ErrorMsgException& c) {Msg=c.Msg?strdup(c.Msg):NULL;}; //copy constructor (compiler sometimes copies exception objects) virtual ~ErrorMsgException() {if (Msg) delete Msg;} #if defined(_Windows) && !defined(QUICKWIN) && !defined(__CONSOLE__) virtual void postMessage (HWND post=0, char severity='E') { #else virtual void postMessage (int post=0, char severity='E') { #endif ::error(post,severity,"%s%s%s",msg(),Msg?": ":".",Msg?Msg:""); }; virtual const char* msg() const=0; }; #define DECL_EXCEPT_ABS_CLASS(declAttr,className,base) \ class declAttr className : public base { \ public: \ className(const char* msg=NULL):base(msg){};} #define DECL_EXCEPT_CLASS(declAttr,className,base,message) \ class declAttr className : public base { \ public: \ className(const char* msg=NULL):base(msg){}; \ virtual const char* msg() const {return message;};} #endif //ERROR_H