Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cExceptionBase.h
Go to the documentation of this file.
1 //
8 
9 #ifndef _INC_cExceptionBase_H
10 #define _INC_cExceptionBase_H
11 #ifndef NO_PRAGMA_ONCE
12 #pragma once
13 #endif
14 
15 #include "cPtrFacade.h"
16 #include "StrT.h"
17 #include "cObject.h"
18 #include "cLogLevel.h"
19 #ifndef _MFC_VER // NOT using _MFC_VER.
20 #include <exception> // use STL based exception class.
21 #endif
22 
23 namespace Gray
24 {
25 
26 #if ! defined(_CPPUNWIND) // STL _HAS_EXCEPTIONS
27  class cExceptionBase // stub this out if no throws allowed.
28  {
31  public:
32  virtual ~cExceptionBase()
33  {
34  }
35  virtual const char* what() const THROW_DEF = 0; // can throw ? strange.
36  };
37 #elif defined(_MFC_VER)
38  // MFC throw a pointer to this structure to track an error. must call Delete() to destruct.
39  // NOTE: cannot be instantiated on the stack. MUST be "new CException" as per MFC rules.
40  // base for to MFC CFileException is CException
41  typedef ::CException cExceptionBase;
42 #else
43  // throw a reference to this structure to track an error. auto destruct as normal class.
44  typedef std::exception cExceptionBase;
45 #endif
46 
47  class GRAYCORE_LINK cException; // Base for my custom exceptions. Also based on cExceptionBase
48 
49  // Abstract the several different types of exception handling as macros.
50 #if ! defined(_CPPUNWIND) // No exception allowed. use STL _HAS_EXCEPTIONS ?
51  // #define GRAY_THROW // no throws allowed.
52 #define GRAY_TRY if (true) {
53 #define GRAY_TRY_CATCH(c,ex) } else if (false) {
54 #define GRAY_TRY_CATCHALL } else {
55 #define GRAY_TRY_END }
56 #elif defined(_MFC_VER)
57  // MFC TRY/CATCH/AND_CATCH/END_CATCH
58 #define GRAY_THROW throw new // throw dynamic "new" pointer (MFC). This is usually BAD practice in modern times.
59 #define GRAY_TRY TRY
60 #define GRAY_TRY_CATCH(c,ex) CATCH(c,ex) // c=cExceptionBase
61 #define GRAY_TRY_CATCHALL CATCH(CException,ex) // CATCH_ALL is weird. needs END_CATCH_ALL
62 #define GRAY_TRY_END END_CATCH
63 #elif defined(_MSC_VER)
64  // STL xstddef _TRY_BEGIN/_CATCH/_CATCH_ALL/_CATCH_END
65 #define GRAY_THROW throw // throw reference (STL)
66 #define GRAY_TRY _TRY_BEGIN
67 #define GRAY_TRY_CATCH(c,ex) _CATCH(c& ex) // c=cExceptionBase
68 #define GRAY_TRY_CATCHALL _CATCH_ALL
69 #define GRAY_TRY_END _CATCH_END
70 #else // __linux__
71 #define GRAY_THROW throw // throw reference (STL)
72 #define GRAY_TRY try {
73 #define GRAY_TRY_CATCH(c,ex) } catch (c& ex) { // c=cExceptionBase
74 #define GRAY_TRY_CATCHALL } catch (...) {
75 #define GRAY_TRY_END }
76 #endif
77 
78 };
79 
80 #endif // _INC_cExceptionBase_H
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define THROW_DEF
Definition: HResult.h:25
Definition: cExceptionBase.h:28
virtual ~cExceptionBase()
Definition: cExceptionBase.h:32
virtual const char * what() const THROW_DEF=0
Definition: cException.h:83
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14