Code::Blocks  SVN r11506
cbexception.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  */
5 
6 #ifndef CBEXCEPTION_H
7 #define CBEXCEPTION_H
8 
9 #include <wx/string.h>
10 #include <wx/log.h> // for wxSafeShowMessage()
11 
12 #include "globals.h" // for cbC2U()
13 
24 {
25  public:
26  cbException(const wxString& msg, const wxString& file, int line);
27  virtual ~cbException();
28 
33  void ShowErrorMessage(bool safe = true);
34 
35  // public members
38  int Line;
39 };
40 
41 #if wxUSE_UNICODE
42  #define cbThrow(message) throw cbException(message, cbC2U(__FILE__), __LINE__)
43 #else
44  #define cbThrow(message) throw cbException(message, __FILE__, __LINE__)
45 #endif
46 
47 #ifndef cbDEBUG
48  #define cbAssert(expr)
49 #else
50  // In unix we use kill to terminate the application, that makes gdb
51  // keep it alive which makes debugging easier.
52  // (thanks go to an unknown author)
53  #ifdef __WXMSW__
54  #define DIE() exit(1)
55  #else
56  #include <csignal>
57  #define DIE() kill(getpid(), SIGINT)
58  #endif
59 
60  #if wxUSE_UNICODE
61  #define cbAssertMessage(expr) \
62  wxString err; \
63  err.Printf(_T("Assertion failed in %s at %s:%d.\n\n%s"), cbC2U(__PRETTY_FUNCTION__).wx_str(), cbC2U(__FILE__).c_str(), __LINE__, cbC2U(#expr).c_str());
64  #else
65  #define cbAssertMessage(expr) \
66  wxString err; \
67  err.Printf(_T("Assertion failed in %s at %s:%d.\n\n%s"), __PRETTY_FUNCTION__, __FILE__, __LINE__, #expr);
68  #endif
69 
70  // non-fatal assertion
71  #define cbAssertNonFatal(expr) \
72  if (!(expr)) \
73  { \
74  cbAssertMessage(expr); \
75  wxSafeShowMessage(_T("Assertion error"), err); \
76  }
77 
78  // fatal assertion
79  #define cbAssert(expr) \
80  if (!(expr)) \
81  { \
82  cbAssertMessage(expr); \
83  wxSafeShowMessage(_T("Fatal assertion error"), err); \
84  DIE(); \
85  }
86 #endif
87 
88 #endif // CBEXCEPTION_H
wxString File
The file where the exception was raised.
Definition: cbexception.h:37
#define DLLIMPORT
Definition: settings.h:16
int Line
The line in the file where the exception was raised.
Definition: cbexception.h:38
wxString Message
The exception&#39;s error message.
Definition: cbexception.h:36
Code::Blocks error handling unit.
Definition: cbexception.h:23