#pragma once /* --------------------------------------------------------------------------- The KException namespace wraps the exception classes. KExceptionAbstract class is the abstract base class from which the KWinException and the KDxException classes are derived. FIXIT: Make KExceptionAbstract a true abstract class, to prevent its instantiaiton. NOTE: The constructors and destructors of derived classes call the abstract class constructors. Hence before virtualisation implement the constructors in derived classes. TODO: Find a way to prevent overloading the Test function by hand coding each variation varying on the data-type of test_val. Elegant solution needed. [Revision: Jan 29 2008] FIXED: KException is now an abstract class. It only implements the three SetErrLine, SetErrFileName and SetErrFuncName, all else is delegated to KWinException. Test is more elegantly implemented as a template. It morphs at runtime. TODO: Could Test be called without a WinException object being instantiated? NOTE: Note that most of the return values of WinAPI functions are fundamentally 'void *' (PVOID), bool and int. So testing for zero should help us for the time being. Class methods are no more defined in separate compilation units (.cpp files) but in the same header file. This is a C++ stipulation that requires the template declaration and definition to be together in one place. [Revision: Mar 07 2008] FIXIT: Keeping declarations with dx and win error handling in a .h and then including the .h in a .cpp and main.cpp throws up linker errors saying multiple declaration of symbols in main.obj and the object module of the new code that uses error handling. Refer to: http://www.codeguru.com/forum/showthread.php?p=1693922#post1693922 FIXED: Moved all non-inline non-template member function implementations to their own compilation units, i.e. .cpp files. ---------------------------------------------------------------------------*/ #include #include using namespace std; namespace KException { class KExceptionAbstract { protected: int err_code; string err_string; string err_description; string err_filename; int err_line; string err_funcname; string err_msg; public: template void SetErrCode(T); template void SetErrString(T); template void SetErrDescription(T); void SetErrFileName(const string); void SetErrLine(const int); void SetErrFuncName(const string); void ConstructErrorMsg(void); void DisplayErrorMsg(void); void WriteErrorMsg(void); template void Test(T test_val, const string file_name, const int line_num, const string func_name) = 0; }; } // namespce KException.